2014-09-03 46 views
-1

我有這段代碼。如何在php變量中存儲javascript值

它對第一個變量工作正常,但它顯示第二個未定義的變量。

我想如何解決這個問題?

這裏是我的代碼:

<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

你必須相反順序

<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>"; 
    ?> 
相關問題