首页 > 文章列表 > 当HTML中的文件不可用时执行脚本?

当HTML中的文件不可用时执行脚本?

JavaScript HTML 文件处理
296 2023-09-16

当文件在 HTML 中不可用或为空时,使用 HTML 中的 onemptied 属性来执行脚本。

示例

您可以尝试运行以下代码来实现 onemptied 属性 -

<!DOCTYPE HTML>
<html>
   <body>
      <video width = "300" height = "200" controls onemptied ="display()">
         <source src = "/html5/foo.ogg" type = "video/ogg" />
         Your browser does not support the video element.
      </video>
      <script>
         function display()
         {
            alert ("Sorry! Empty playlist!");
         }
      </script>
   </body>
</html>