Joh*_*ohn 5 html javascript audio jquery
我<audio>
在 HTML5 中没有看到太多关于标签的文档。我试图在音频播放完毕后触发一个事件。
HTML:
<audio id="audio">
<source src="'.$query['audioPronunciation'].'" type="audio/mp3">
Your browser does not support the audio element.
</audio>
Run Code Online (Sandbox Code Playgroud)
JavaScript / jQuery 播放和暂停:
function audio() {
if ($("#audioControl").hasClass("glyphicon-play")) {
$("#audioControl").addClass("glyphicon-pause").removeClass("glyphicon-play");
$("#audio").trigger("play");
} else if ($("#audioControl").hasClass("glyphicon-pause")) {
$("#audioControl").removeClass("glyphicon-pause").addClass("glyphicon-play");
$("#audio").trigger("pause");
}
}
Run Code Online (Sandbox Code Playgroud)
JavaScript / jQuery,“结束时”
$("#audio").addEventListener('ended', function() {
alert("Audio has finished playing!");
Run Code Online (Sandbox Code Playgroud)
});
您不需要事件侦听器,只需:
var audio1 = document.getElementById("myAudio1");
audio1.onended = function() {
alert("audio playback has ended");
};
Run Code Online (Sandbox Code Playgroud)