在 HTML 中,當媒體開始播放時執行指令碼?


使用 oncanplay  屬性定義音訊/影片何時開始播放。

示例

可以嘗試執行以下程式碼,以瞭解如何在媒體準備好播放時執行指令碼 −

<!DOCTYPE html>
<html>
   <body>
      <video id = "myid" width = "320" height = "176" controls oncanplay="display()">
         <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() {
            alert("Video loaded!");
         }
      </script>
   </body>
</html>

更新日期:30-5-2020

123 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

立即上手
廣告
© . All rights reserved.