我这里有一个JavaScript嵌入到一个PHP脚本"echo“中。当我使用警报框中的document.getElementById('list_subjects').selectedIndex
时,它会给出结果,但是当我在php数组变量中使用它时。上面写的是未定义的索引。我使用(int)$index
将其转换为整数,但它的输出始终是零。这里有什么问题?谢谢!
<?php
echo "<script> function subject_name(){" . ($index = "(document.getElementById('list_subjects').selectedIndex)") . ";document.getElementById('subj_name').innerHTML = '" . ($list_options_name[(int)$index]) . "';} </script>";
?>
发布于 2013-11-01 23:43:00
$index = "(document.getElementById('list_subjects').selectedIndex"
上面的行不会将selectedIndex存储在$index
的值中,PHP是服务器端脚本语言,JS是客户端。上面的行无效。
应该使用ajax调用访问/传递这些值。
https://stackoverflow.com/questions/19739874
复制