HTML中如何執行一個指令碼,當媒體內容的播放位置發生變化時?


ontimeupdate屬性事件在播放媒體,比如影片,的播放位置改變的時候觸發。可以在影片或音訊中進行快進或後退。

示例

你可以嘗試執行下面的程式碼來實現ontimeupdate屬性−

<!DOCTYPE html>
<html>
   <body>
      <h2 id="test">Play</h2>
      <video id = "myid" width="320" height = "176" controls ontimeupdate = "myFunction()">
         <source src = "/html5/foo.ogg" type = "video/ogg" />
         <source src = "/html5/foo.mp4" type = "video/mp4" />
         Your browser does not support the video element.
      </video>
      <script>
         function myFunction() {
            document.getElementById("test").innerHTML = "Current position: " +
            document.getElementById("myid").currentTime;
         }
      </script>
   </body>
</html>

更新日期: 24-Jun-2020

71次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告