如何将php值传递给脚本变量

时间:2016-12-13 09:48:13

标签: javascript php html

我有一个php变量值,我们必须在按钮点击时自动将它传递给脚本变量。请建议我。

Data

当我点击按钮<?php $query2 = mysql_query("select * from video_detail where video_id='$id' and status=1"); while( $qry2 = mysql_fetch_array($query2)){ $part1 = $qry2["part"]; $from1 = $qry2["from"]; $to1 = $qry2["to"]; ?> <button><? echo $part1;?></button><? }?><br> <video style="border:1px solid" id="myVideo" width="320" height="176" controls> <source src="uploads/videos/<?php echo $vid;?>" type="video/mp4"> </video> <script> var video = document.getElementById('myVideo'); var videoStartTime = 0; var durationTime = 0; video.addEventListener('loadedmetadata', function() { videoStartTime = 2; durationTime = 4; this.currentTime = videoStartTime; }, false); video.addEventListener('timeupdate', function() { if(this.currentTime > videoStartTime + durationTime){ this.pause(); } }); </script> 传递给$from1 = ??的值时;并且videoStartTime值传递给$to1 = ??;

1 个答案:

答案 0 :(得分:0)

做类似的事情:

<script> 

    var form1 = <?= $form1 ?>;
    var to1 = <?= $to1 ?>;

 </script>

在按钮中添加一个事件,如:

<button onclick="myFunction()">Click</button>

当onclick事件发生时,覆盖此函数内的值:

function myFunction(){
   videoStartTime = form1;
   durationTime = to1;
}