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>
<input type="hidden" value="100">
</form>
<script type="text/javascript">
jsvar = document.myform4.formvar.value;
document.write(jsvar) // test
</script>


PHP variable to Form variable:

复制代码 代码如下:


<form>
<input type="hidden" value="<?php $phpvar=10; echo $phpvar; ?>"> // PHP code inside HTML!!
</form>


Javascript variable to Form variable:

复制代码 代码如下:


<form>
<!-- It needn't be a "hidden" type, but anything from radio buttons to check boxes -->
<input type="hidden" value="">
</form>
<script type="text/javascript">
jsvar=10;
document.myform3.formvar.value = jsvar;
</script>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/9133c9d5e47c7c03e642141111476629.html