<?php
$heros=array("Spiderman","Batman","Superman");
?>
<script type="text/javascript">
var heros = <?php echo $heros;?> // I don't want to do this.
for(i=0; i<3; i++)
{
if(heros[i]=='Spiderman')
{
alert('Hey! I am Spiderman.');
}
}
</script>
我想在 javascript for 循环中使用 php 数组,但我不想在标签内重新打开 php<script></script>
标签。如何在 javascript 中使用 php 变量?