代码编辑器:
x
1
<p>演示了如何使用 addEventListener() 方法 向 video 元素中添加 "oncanplay" 事件</p>
2
<video controls id="myVideo">
3
<source src="/static/i/html/html_video_2.mp4" type="video/mp4">
4
<source src="/static/i/html/html_video_2.ogg" type="video/ogg">
5
您的浏览器不支持 HTML5 video 元素。
6
</video>
7
<script>
8
document.getElementById("myVideo").addEventListener("canplay", myFunction);
9
function myFunction() {
10
alert("可以开始播放视频");
11
}
12
</script>
13