如何能实现打开网站就可以播放音乐
比如这个网站:https://www.cvf.org.cn/我知道答案 回答被采纳将会获得5 金币 已有1人回答 <!-- 背景音乐 --> <script> function hasClass(ele,cls) { return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); } function musicPalyer(obj){ var myAuto =document.getElementById('musicPalyer'); var playerBtn = document.getElementById('player_btn'); var boolClass = hasClass(playerBtn,'close_player'); if(boolClass){ myAuto.pause(); //暂停播放 playerBtn.className="player"; }else{ myAuto.play(); playerBtn.className +=" " + 'close_player'; } } </script> <style> .player{background:url(https://www.cvf.org.cn/cvf/images/player-r.png) no-repeat 50% 50%;width: 24px;height: 24px;display: block;float: right;text-indent: -9999px;margin-top:5px;} .player.close_player{background:url(https://www.cvf.org.cn/cvf/images/player-d.png) no-repeat 50% 50%;} </style> <audio autoplay="" id="musicPalyer"> <source src="https://www.cvf.org.cn/cvf/images/dbs.mp3" type="audio/mpeg"> </audio> <a href="javascript:void(0);" target="_self" id="player_btn" class="player close_player" onclick="musicPalyer(this)"></a>
页:
[1]