最奇怪的是:我有一个jQuery函数可以改变音频播放器的来源。如果我在其间插入“alert()”,它就有效。但否则它会返回NaN。
jQuery的:
$('.playpause').click(function(){
if (playmode==false){
audio = $('#player audio').get(0);
$(audio).attr('src','newurl.mp3');
playmode = true;
/*alert('wait a minute!');*/
audio.play();
}
else {
audio.pause();
playmode = false;}
})
我想这与浏览器没有时间加载数据有关?有什么想法吗?谢谢!
答案 0 :(得分:0)
与我完美配合:>>
<script>
jQuery(document).ready(function ($) {
$('.button').click(function(){
var myAudio=$(".playpause");
var audioSub = myAudio.get(0);
var playmode=audioSub.paused;
if (playmode){
myAudio.attr('src','song.mp3');
playmode = true;
audioSub.play();
}
else {
audioSub.pause();
playmode = false;}
})
});
</script>
HTML代码:&gt;&gt;
<button class="button" >Next</button>
<audio controls class="playpause">
<source src="song0.mp3" type="audio/mp3"/>
Your browser does not support HTML5 audio.
</audio>