|
复制代码 代码如下:
<?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>
php技术:php和javascript之间变量的传递实现代码,转载需保留来源!
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。