php和javascript之間變量的傳遞實現(xiàn)代碼
更新時間:2012年12月19日 10:46:58 作者:
本文提供一種解決php和javascript之間變量的傳遞的方法,需要的朋友可以參考下
PHP variable to Javascript variable:
<?php $myvar=10; ?>
<script type="text/javascript">
jsvar = <?php echo $myvar; ?>;
document.write(jsvar); // Test to see if its prints 10:
</script>
Form variable to Javascript variable:
<form name="myform4">
<input type="hidden" name="formvar" value="100">
</form>
<script type="text/javascript">
jsvar = document.myform4.formvar.value;
document.write(jsvar) // test
</script>
PHP variable to Form variable:
<form name="myform4">
<input type="hidden" name="formvar" value="<?php $phpvar=10; echo $phpvar; ?>"> // PHP code inside HTML!!
</form>
Javascript variable to Form variable:
<form name="myform3">
<!-- It needn't be a "hidden" type, but anything from radio buttons to check boxes -->
<input type="hidden" name="formvar" value="">
</form>
<script type="text/javascript">
jsvar=10;
document.myform3.formvar.value = jsvar;
</script>
復(fù)制代碼 代碼如下:
<?php $myvar=10; ?>
<script type="text/javascript">
jsvar = <?php echo $myvar; ?>;
document.write(jsvar); // Test to see if its prints 10:
</script>
Form variable to Javascript variable:
復(fù)制代碼 代碼如下:
<form name="myform4">
<input type="hidden" name="formvar" value="100">
</form>
<script type="text/javascript">
jsvar = document.myform4.formvar.value;
document.write(jsvar) // test
</script>
PHP variable to Form variable:
復(fù)制代碼 代碼如下:
<form name="myform4">
<input type="hidden" name="formvar" value="<?php $phpvar=10; echo $phpvar; ?>"> // PHP code inside HTML!!
</form>
Javascript variable to Form variable:
復(fù)制代碼 代碼如下:
<form name="myform3">
<!-- It needn't be a "hidden" type, but anything from radio buttons to check boxes -->
<input type="hidden" name="formvar" value="">
</form>
<script type="text/javascript">
jsvar=10;
document.myform3.formvar.value = jsvar;
</script>
相關(guān)文章
PHP圖片處理之使用imagecopyresampled函數(shù)實現(xiàn)圖片縮放例子
這篇文章主要介紹了PHP圖片處理之使用imagecopyresampled函數(shù)實現(xiàn)圖片縮放例子,本文先是講解了imagecopyresampled函數(shù)的相關(guān)知識,然后給出了實現(xiàn)代碼例子,需要的朋友可以參考下2014-11-11
Uncaught exception com_exception with message Failed to crea
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `InternetExplorer.Application': 拒絕訪問2012-01-01
php程序的國際化實現(xiàn)方法(利用gettext)
這里我們主要介紹window平臺下使用php的擴展gettext實現(xiàn)程序的國際化。2011-08-08

