js call PHP variables, how to get the example on the Web is a JS file in the beginning to give this variable a value, if that is what the meaning of Ah, I want is can change. hychyc_2008 | browse 2,741 times 2013-04-18 12:24 2013-04-20 10:34Best Answer
<script>
var str=<?php echo $value;? >
</script>
This practice I used before, some browsers can, some browsers will not recognize. Specific is IE several I forget ~ ~ ~
It seems that IE6 didn't recognize it.
My approach is to:
<?php
echo "
<script>
var str= $value;
</script> ";
?>
This is sure to be fine.
This answer is recommended by the questionerComments (1)0
Front_diablo
Adoption Rate: 37% good: Not customized
Other answersvar str=<?php echo $value;? > is assigning values directly to variables. If JS is an external file, can be written in the form of a function, called when the parameters are assigned to PHP, such as AA (<?php echo $value; >)Miss Oba 芓 | 2013-04-18 13:18 Reviews2 1
| 123456 |
<scripttype="text/javascript">if(str==<?phpecho $str;?>){ alert(3333333333);}</script> |
Mbseo | 2013-04-18 12:45 Reviews0 0 This is not allowed, PHP is the server-side compiler language, JS is the browser-side interpretation language. Zuoyiduohua | 2013-04-18 12:38 Reviews0 3 then you get it dynamically with Ajax .123010wqq | 2013-04-18 12:29 Reviews0 0 var str=<?php echo $value;? >zhx626 | 2013-04-18 12:27
JS calls the variables in PHP, how do you get it?