在 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.