HTML 中媒體播放結束時如何執行指令碼?


使用 HTML 中的 onended 屬性可在媒體在 HTML 中播放完畢時執行指令碼。你可以新增類似“感謝觀看”、“敬請期待”等訊息。

示例

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

<!DOCTYPE HTML>
<html>
   <body>
      <video width = "300" height = "200" controls onended = "display()">
         <source src = "/html5/foo.ogg" type = "video/ogg" />
         Your browser does not support the video element.
      </video>
      <script>
         function display() {
            alert ("Thank you for watching! Stay tuned!");
         }
      </script>
   </body>
</html>

更新於: 03-Mar-2020

70 次瀏覽

開啟你的 職業征程

完成課程後獲得認證

開始
廣告