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


當 HTML 中音訊/影片的長度發生變化時,ondurationchange 屬性會被觸發。

示例

你可以執行以下程式碼嘗試實現 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 次瀏覽

啟動您的職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.