HTML代码:
<audio id="myaudio" loop="loop" preload="auto" autoplay="autoplay">
<source src="music/纯音乐%20-%20在那遥远的地方%20-%20纯音乐版.mp3" type="audio/ogg" />
<source src="music/纯音乐%20-%20在那遥远的地方%20-%20纯音乐版.mp3" type="audio/mp3" />
</audio>
<img οnclick="swap_music()" src="/images/icon_music.png" style="height:30px; vertical-align:middle;" />
JS代码:
//背景音乐停止与播放
function swap_music() {
var oAudio = document.getElementById('myaudio');
if (oAudio.paused) {
oAudio.play();
}
else {
oAudio.pause();
}
}
<audio id="myaudio" loop="loop" preload="auto" autoplay="autoplay">
<source src="music/纯音乐%20-%20在那遥远的地方%20-%20纯音乐版.mp3" type="audio/ogg" />
<source src="music/纯音乐%20-%20在那遥远的地方%20-%20纯音乐版.mp3" type="audio/mp3" />
</audio>
<img οnclick="swap_music()" src="/images/icon_music.png" style="height:30px; vertical-align:middle;" />
JS代码:
//背景音乐停止与播放
function swap_music() {
var oAudio = document.getElementById('myaudio');
if (oAudio.paused) {
oAudio.play();
}
else {
oAudio.pause();
}
}