单击按钮后播放的HTML音频

时间:2014-04-28 10:33:42

标签: javascript jquery html5 audio

单击按钮1时如何播放音频,单击按钮2或3时暂停/停止?

<a href="#" class="button1">Button 1</a>
<a href="#" class="button2">Button 2</a>
<a href="#" class="button3">Button 3</a>


<audio controls autoplay loop>
   <source src="<?php bloginfo('template_directory'); ?>/audio/audio1.ogg" type="audio/ogg">
   <source src="<?php bloginfo('template_directory'); ?>/audio/audio1.mp3" type="audio/mpeg">
   Your browser does not support the audio tag.
</audio> 

2 个答案:

答案 0 :(得分:0)

$(".button1").click(function() {
    $("audio")[0].play();

});

$(".button2").click(function() {
    $("audio")[0].pause();
});

答案 1 :(得分:0)

$(".button1").click(function(){
   $('audio')[0].play();
}) 

$(".button2").click(function(){
   $('audio')[0].pause();
}) 

http://jsfiddle.net/8GycB/3/