当前位置: 代码迷 >> JavaScript >> 求好手精简此段代码
  详细解决方案

求好手精简此段代码

热度:152   发布时间:2012-07-24 17:47:58.0
求高手精简此段代码
JScript code

function play3(i) {

    if (i == 1) {
        audio.currectTime = 0;
        audio.play();
        i = i + 1;
        setTimeout("play3(2)", 2000);
    } else if (i == 2) {
        audio.currectTime = 0;
        audio.play();
        i = i + 1;
        setTimeout("play3(3)", 2000);
    } else if (i == 3) {
        audio.currectTime = 0;
        audio.play();
        i = i + 1;
        setTimeout("play3(4)", 2000);
    } else if (i == 4) {
        audio.currectTime = 0;
        audio.play();
        i = i + 1;
    }

}



------解决方案--------------------
JScript code
function play3(i) {
    audio.currentTime = 0;
    audio.play();
    if (i == 1 || i == 2 || i == 3) setTimeout("play(" + (i + 1) + ")", 2000);
    i += 1;
}

------解决方案--------------------
function play3(i) {
audio.currectTime = 0;
audio.play();
i = i + 1;
if(i != 5){
setTimeout("play3("+i+")", 2000);
}
}

这个意思?
  相关解决方案