2012-07-27 183 views
0

我想製作一個使用jquery的音頻播放器,並且似乎有這樣做的一些問題。我可以阻止音樂,但我似乎無法再播放它。使用jquery切換音頻播放器的播放/暫停按鈕

HTML:

<footer> 
     <nav> 
      <div id="buttons"> 
       <buttons type="button" id="playbutton">Stop Music</button> 
      </div> 
     </nav> 
    </footer> 
    <audio id="Theme" autoplay> 
     <source src="BillaTheme.mp3"/> 
    </audio> 

的Jquery:

$("document").ready(function(){      
     $("#playbutton").click(function() { 
        if (!$("#Theme").paused) 
        { 
         $("#Theme")[0].pause();   
         $("#playbutton").text("Play Music"); 
        } 
        else 
         { 
          $("#Theme")[0].play();   
          $("#playbutton").text("Stop Music"); 
         } 
       }); 
}); 

不知道哪裏出錯..需要一些指導...

+0

'$(「文件」)'應該是'$(文件)'(即使結合就緒事件時,元素集被忽略) – ThiefMaster 2012-07-27 14:29:16

回答

3

$("#Theme").paused需求是$("#Theme")[0].paused - 否則,你訪問jQuery對象的屬性不起作用。

爲了提高可讀性添加var player = $("#Theme")[0];然後用player.pausedplayer.play()

+0

否則邏輯正確的權利? – lakesh 2012-07-27 14:37:16

+0

是的,看起來是正確的。 – ThiefMaster 2012-07-27 14:53:11