using JS variable in PHP
问题 how can use JS variable in PHP like this ? <script> x = document.getElementById(1).value; var listOf = <?php echo $listOf[x]; ?>; </script> this doesn't work :( 回答1: And rightfully so. PHP is executed on the server , while JavaScript is executed in the client's browser . Those are two different contexts and the variables from one are not visible in the second. You need to have your PHP script output a JavaScript version of the array and then use this one in your script. Something like this: <