js播放背景音乐失败处理
<script> const music = new Audio('med/CanonInD.mp3'); music.loop =true; document.addEventListener("DOMContentLoaded", function(event) { console.log("页面加载完毕"); if (music.paused) { //console.log('音频当前没有播放'); music.play(); /*可能报错*/ } }); //屏幕点击事件 window.addEventListener('click', function(event) { if (music.paused) { //console.log('音频当前没有播放'); music.play(); }else{ console.log('音频已经在播放'); } }); </script>