【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>

posted @ 2022-06-05 17:35  木子欢儿  阅读(374)  评论(0编辑  收藏  举报