$result = mysql_query(.....);//连接、读取等等。。
$row = mysql_fetch_array($result);
echo "<script>alert(".$row("col1").");</script>"//用javascript显示
$row = mysql_fetch_array($result);
echo "<script>alert(".$row("col1").");</script>"//用javascript显示
这样不会被js说成是无效果变量啊?因为在js里没有$xxxx的说法呀
var result=<?php echo $result; ?>
<head><title>title...</title>
</head>
<body>
<?php
//连接数据库、读取等等........
?>
<script>
alert('<?php $row("col1"); ?>');
</script>
</body>
</html>明白吗?
这样不会被js说成是无效果变量啊?因为在js里没有$xxxx的说法呀楼主没有看清楚,是echo "<script>var result=$result</scirpt>";
这是php里的输出语句。输出后直接将$result变量的值输出到js里的result变更了。
<script>
var js_var=<?=$php_var?>
</script>
示例:
<?php
print "<script language=javascript>document.write($row);</script>";
?>