如何将PHP变量的值传递给javascript [英] How to pass value of PHP variable to javascript
本文介绍了如何将PHP变量的值传递给javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用此代码将$ i的值传递给脚本..但它不起作用
< html >
< head >
< link rel = 样式表 type = text / css href = Styles\style.css / >
< title > iFound < / title >
< / head >
< body dir = rtl >
< div id = MainDiv >
< div id = Headin > < / div >
< div id = 导航 > < / div >
<? php
for($ i = 0; $ i< 10; $ i ++)
{
echo < div class = \divs \ ><二v class = \indivs\>< / div>< div class = \intxtdivs \>< / div>< / div>;
}
echo < ; script type ='text / javascript'language ='javascript'>
var a = 5;
a ='<?php echo $ i;?>';
document。写(a);
< / script>
?>
< / div >
< / body >
< / html >
我的尝试:
a =;
a =;
解决方案
我对脚本..但是它无法正常工作
< span class =code-keyword>< html >
< head >
< link rel = stylesheet 类型 = text / css href = Styles\style.css / >
< title > iFound < / title >
< / head >
< body dir = rtl >
< div id = MainDiv >
< div id= Headin > < / div >
< span class =code-keyword>< div id = 导航 > < / div > ;
<? php
for(
i = 0;
I< 10;
I tried this code to pass the value of $i to the script .. but it is not working
<html>
<head>
<link rel="stylesheet" type="text/css" href="Styles\style.css"/>
<title>iFound</title>
</head>
<body dir="rtl">
<div id="MainDiv">
<div id="Headin"></div>
<div id="Nav"></div>
<?php
for($i=0;$i<10;$i++)
{
echo "<div class=\"divs\"><div class=\"indivs\"></div><div class=\"intxtdivs\"></div></div>";
}
echo "<script type='text/javascript' language='javascript'>
var a = 5;
a = '<?php echo $i;?>';
document.write(a);
</script>"
?>
</div>
</body>
</html>
What I have tried:
a = ;
a = "";
解决方案
i to the script .. but it is not working
<html> <head> <link rel="stylesheet" type="text/css" href="Styles\style.css"/> <title>iFound</title> </head> <body dir="rtl"> <div id="MainDiv"> <div id="Headin"></div> <div id="Nav"></div> <?php for(
i=0;
i<10;
这篇关于如何将PHP变量的值传递给javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文