【JS】实现点击图标播放音乐
<img src="img/music.png" alt="" class="musicBtn" onclick="bgaudio()" >
<audio src="https://quickso.cn/api/wyy/api.php?id=1474411443" id="bgaudio" ></audio>
<script>
var bgaudiocount = 0;
function bgaudio(){
++bgaudiocount;
if(bgaudiocount % 2 == 1){
document.getElementById("bgaudio").play();
}else{
document.getElementById("bgaudio").pause();
}
}
</script>
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/16344450.html