日期:2014-05-16  浏览次数:20408 次

求高手精简此段代码
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);
}
}

这个意思?