每篇文章仅做为自己的备忘笔记,若有描述不清或不对的地方还请指明,感谢^_^

计时器

//<editor-fold desc="倒计时事件  调用countDown(id,显示的文本)">
var time = 5;//倒计时的时间
var showTimeId = "";//显示倒计时的位置
var showTimeText = "";//倒计时结束的文本

async function countDown(id, text) {

    if (time >= 5) {
        showTimeId = id;
        showTimeText = text;
        startTime();
    }else {
        console.log("stop!")
    }
}

function startTime() {
    time = time - 1;
    $("#" + showTimeId).html(time + "秒");
    if (time == 0) {
        $("#" + showTimeId).html(showTimeText);
        time = 5;
        clearTimeout();
        return;
    }
    console.log(time);
    setTimeout('startTime()', 1000);
}

//</editor-fold>

 

posted @ 2019-10-18 00:57  菜汤不甜  阅读(138)  评论(0编辑  收藏  举报