2012-08-26 42 views

回答

3
first.addEventListener('ended', function(){ 
    second.play(); 
}); 
first.play(); 
+0

但是,如果我想連續播放許多文件,我會在看回調地獄。任何方式來介紹.then()承諾像語法? – whamsicore

0

我會推薦一種東西:

// if using jQuery: 
var audios = $('audio'); 

audios.each(function(idx){ 
    $(this).bind('ended', function(){ 
     var next = audios.get(idx+1); 
     if(next){ 
      next.get(0).play(); 
     } 
    }); 
});