0

这是我已经废弃的脚本,它只是一个基本的停止时间监视脚本,我想要一些关于如何添加恢复和开始按钮的输入。我希望能够在它停止时暂停时启动时发送 ajax 调用。

var timer;
$(function () {
    $('#dateTime').html(getDateTime());
    timer = setTimeout(function () {
        update();
    }, 1000);
    $('#btn').click(function () {
        clearTimeout(timer);
        var currentdatetime = getDateTime();
    });
});

function update() {
    $('#dateTime').html(getDateTime());

    timer = setTimeout(function () {
        update();
    }, 1000);
}

function getDateTime() {
    var currentdate = new Date();
    var datetime = "Timer: " + currentdate.getDate() + "/" + (currentdate.getMonth() + 1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
    return datetime;
}
4

1 回答 1

0
var timer;

function resume() {
    update();
    $('#resume').off("click", resume);
    $('#pause').on("click", pause);
    // make start / resume ajax call here
}

function pause() {
    clearTimeout(timer);
    $('#resume').on("click", resume);
    $('#pause').off("click", pause);
    // make pause / stop ajax call here
}

function update() {
    $('#dateTime').html(getDateTime());

    timer = setTimeout(function () {
        update();
    }, 1000);
}

function getDateTime() {
    var currentdate = new Date();
    var datetime = "Timer: " + currentdate.getDate() + "/" + (currentdate.getMonth() + 1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
    return datetime;
}

$(function () {
    resume();
});
于 2013-10-31T03:46:19.790 回答