We called the javascript script, playPause() function when we clicked the switch image button. The function determines the audio playback state. If it has been stopped (paused), call .play() to continue playing. If it is in the playing state, immediately pause playback.pause(). When the two states switch, the button image is updated in time. Please see Code: JavaScript CodeCopy content to clipboard
function playPause() {
var music = document.getElementById('music2');
var music_btn = document.getElementById('music_btn2');
if (music.paused){
music.play();
music_btn.src = 'play.gif';
}
else{
music.pause();
music_btn.src = 'pause.gif';
}
}
If you use jQuery code, you can write it like this:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn