php和javascript之間變量的傳遞實(shí)現(xiàn)代碼
更新時(shí)間: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內(nèi)核探索:變量存儲(chǔ)與類型使用說(shuō)明
這篇文章主要介紹了PHP內(nèi)核探索:變量存儲(chǔ)與類型的相關(guān)資料,需要的朋友可以參考下2014-01-01
php模擬用戶自動(dòng)在qq空間發(fā)表文章的方法
這篇文章主要介紹了php模擬用戶自動(dòng)在qq空間發(fā)表文章的方法,可實(shí)現(xiàn)模擬用戶提交表單發(fā)布文章的功能,代碼中包含有較為詳盡的注釋便于理解,需要的朋友可以參考下2015-01-01
PHP圖片處理之使用imagecopyresampled函數(shù)實(shí)現(xiàn)圖片縮放例子
這篇文章主要介紹了PHP圖片處理之使用imagecopyresampled函數(shù)實(shí)現(xiàn)圖片縮放例子,本文先是講解了imagecopyresampled函數(shù)的相關(guān)知識(shí),然后給出了實(shí)現(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': 拒絕訪問(wèn)2012-01-01
php程序的國(guó)際化實(shí)現(xiàn)方法(利用gettext)
這里我們主要介紹window平臺(tái)下使用php的擴(kuò)展gettext實(shí)現(xiàn)程序的國(guó)際化。2011-08-08

