<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title></title> </head> <body> 音樂 <audio src="b.mp3" controls="controls" preload id="music1" hidden> </audio> <span id="bf" onclick="bf();">播放/暫停</span> <span id="bf" onclick="rbf();">從新播放</span> <script> function rbf(){ var audio = document.getElementById('music1'); audio.currentTime = 0; } function bf(){ var audio = document.getElementById('music1'); if(audio!==null){ //檢測播放是否已暫停.audio.paused 在播放器播放時返回false. alert(audio.paused); if(audio.paused) { audio.play();//audio.play();// 這個就是播放 }else{ audio.pause();// 這個就是暫停 } } } </script> </body> </html>