使用oncanplay 属性定义何时可以开始播放音频/视频。
您可以尝试运行以下代码,以学习在媒体准备开始播放时如何执行脚本-
<!DOCTYPE html> <html> <body> <video id = "myid" width = "320" height = "176" controls oncanplay="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("视频已加载!"); } </script> </body> </html>