以下是object
标记中的音频:
<object id="music" data="music.mp3">
<param name="autoplay" value="true" />
<param name="loop" value="true" />
</object>
我希望能够使用几个a
标签暂停/播放音频:
<div id="music-on-off">Music:
<a href="#" id="music-on">On</a> | <a href="#" id="music-off">Off</a>
</div>
你能告诉我jQuery这样做吗?
答案 0 :(得分:1)
使用<audio>
元素,.play()
,.pause()
HTML
<audio src="music.mp3" autoplay loop></audio>
<div id="music-on-off">Music:
<a href="#" id="music-on">On</a> | <a href="#" id="music-off">Off</a>
</div>
的javascript
$(function() {
var audio = $("audio")[0];
var controls = {
"music-on": "play",
"music-off": "pause"
};
function playPause(e) {
e.preventDefault();
audio[controls[this.id]]()
}
$("#music-on, #music-off").click(playPause);
});
jsfiddle http://jsfiddle.net/j3eL1nL8/1/