HTML 中當媒體長度發生變化時執行一個指令碼?


ondurationchange 屬性可在 HTML 中音訊/影片的長度發生變化時觸發。

示例

你可以嘗試執行以下程式碼來實現 ondurationchange 屬性 -

<!DOCTYPE HTML>
<html>
   <body>
      <video width = "300" height = "200" controls ondurationchange = "display(this)">
         <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 display(vLength) {
            alert("Video Length: " + vLength.duration + " seconds");
         }
      </script>
   </body>
</html>

更新於: 03-Mar-2020

161 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告