html限制仅有一个音/视频可播放
function audiosPlay() {
const audios = document.getElementsByTagName('audio');
const videos = document.getElementsByTagName('video');
function pauseAll() {
var self = this;
[].forEach.call(audios, function (i) {
if (i !== self) i.pause();
});
[].forEach.call(videos, function (i) {
i.pause();
});
}
[].forEach.call(audios, function (i) {
i.addEventListener('play', pauseAll.bind(i));
});
}
function videosPlay() {
const audios = document.getElementsByTagName('audio');
const videos = document.getElementsByTagName('video');
function pauseAll() {
var self = this;
[].forEach.call(videos, function (i) {
if (i !== self) i.pause();
});
[].forEach.call(audios, function (i) {
i.pause();
});
}
[].forEach.call(videos, function (i) {
i.addEventListener('play', pauseAll.bind(i));
});
}