:)我尝试只循环播放 HTML5 视频 3 次。我找到了这个代码片段,它基本上可以做我想要的。奇怪的是,我无法让它工作。如果我在堆栈溢出上运行演示,它可以工作。如果我将其复制并粘贴到空白的 html 文档中,它不会。有什么建议吗?
谢谢!
尝试复制+粘贴此内容。这应该有效。
<div>Iteration: <span id="iteration"></span></div>
<video width="320" height="240" id="myVideo" controls>
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" />
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" />
Your browser does not support the video tag.
</video>
<script>
var iterations = 1;
document.getElementById('iteration').innerText = iterations;
myVideo.addEventListener('ended', function () {
if (iterations < 2) {
this.currentTime = 0;
this.play();
iterations ++;
document.getElementById('iteration').innerText = iterations;
}
}, false);
</script>
您是否在
正文部分的末尾添加JS脚本?脚本应添加到正文部分的末尾(加载文档时(。