React中页面多个audio每次只播放一个

直接上代码



 _justPalyOne() {
	const audios = document.querySelectorAll("audio");
		// 暂停函数
		const pauseAll = (exclude)=> {
		  audios.forEach((audio, index) => {
			if (exclude !== index) {
			  audio.pause();
			}
		  });
		};
		audios.forEach((audio, index) => {
		  audio.addEventListener("play", ()=>{pauseAll(index)});
		});
 }

你可能感兴趣的:(react.js,前端,javascript,html5)