function stop(el){
el.pause(); // Stop playing
el.currentTime = 0; // Reset time
}
下面是一个工作示例
id
指定而不是
element
function stop(elementId) {
var el = document.getElementById(elementId);
el.pause(); // Stop playing
el.currentTime = 0; // Reset time
}
<audio id="myAudio" controls>
<source src="http://ccrma.stanford.edu/~jos/mp3/viola.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br/><br/>
<button onclick="stop('myAudio')">Stop playing</button>