|
復(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>
php技術(shù):php和javascript之間變量的傳遞實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。