<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>当前只允许一个视频播放其他暂停</title>
</head>
<body>
<video src="aaa.mp4" controls="controls"></video>
<video src="bbb.mp4" controls="controls"></video>
<script type="text/javascript">
var videos = document.getElementsByTagName('video');
for (var i = videos.length - 1; i >= 0; i--) {
(function(){
var p = i;
videos[p].addEventListener('play',function(){
pauseAll(p);
})
})()
}
function pauseAll(index){
for (var j = videos.length - 1; j >= 0; j--) {
if (j!=index) videos[j].pause();
}
};
</script>
</body>
</html>
订阅评论
0 评论