标签:
var audio = document.createElement("audio");
var index = 0;
audio.src = "piano/3C.mp3";
audio.addEventListener(‘ended‘, function () {
// Wait 500 milliseconds before next loop
setTimeout(function () {if(index<4){ audio.play(); index++}}, 500);
}, false);
audio.play();
这里的index必须设置为全局变量,这是个闭包问题!
var audio = document.createElement("audio");
var index = 0;
audio.src = "piano/3C.mp3";
audio.addEventListener(‘ended‘, function () {
// Wait 500 milliseconds before next loop
setTimeout(function () {if(index<4){ audio.play(); index++}}, 500);
}, false);
audio.play();
标签:
原文地址:http://www.cnblogs.com/yangmengsheng/p/5914755.html