我有这个代码。
它适用于第一个var,但它显示第二个未定义的变量。
我想如何解决这个问题?
这是我的代码:
<script>
var p1 = "success";
var time = document.getElementById("time").innerHTML;
</script>
<body>
<div id="time">04:00</div>
<?php
echo "<script>document.writeln(p1);</script>";
echo $timevalue = "<script>document.writeln(time);</script>";
?>
答案 0 :(得分:0)
你必须颠倒顺序
<div id="time">04:00</div>
<script>
var p1 = "success";
var time = document.getElementById("time").innerHTML;
</script>
<?php
echo "<script>document.writeln(p1);</script>";
echo $timevalue = "<script>document.writeln(time);</script>";
?>