可能重复:
PHP 回显的 Javascript 未运行
在下面的代码中,我将 php 表中的值解析为 javascript 函数,但是我得到了 Uncaught ReferenceError: "the php text" is not defined (anonymous function)
<html>
<script type="text/javascript">
function draw(name ) {
alert(name);
}
</script>
<body>
<canvas id="mycanvas" width=800 height=400></canvas>
</body>
</html>
<?php
$query = 'SELECT * FROM graph_table';
$result = mysql_query($query);
while($val = mysql_fetch_array($result)) {
$name = $val['test_name'];
echo '<script type="text/javascript"> draw('.$name .'); </script>';
}
?>