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


使用onplaying 屬性,便於使用者知曉音訊/影片已開始播放。

示例

可以嘗試執行以下程式碼,瞭解當媒體開始播放後如何執行指令碼 −

<!DOCTYPE html>
<html>
   <body>
      <video id = "myid" width = "350" height = "200" controls onplaying = "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 started playing!");
         }
      </script>
   </body>
</html>

更新時間: 2020 年 5 月 30 日

94 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.