在 HTML 中加载媒体数据时执行脚本?

htmlweb developmentfront end technology更新于 2024/7/29 10:20:17

使用 onloaddata 事件在媒体数据加载时执行脚本。您可以尝试运行以下代码来实现 onloaddata 事件 −

示例

以下代码会在视频加载时生成一个警告框 −

<!DOCTYPE html>
<html>
   <body>
      <video controls onloadeddata = "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("Loaded!");
         }
      </script>
   </body>
</html>

相关文章


有用资源