gpt4 book ai didi

javascript - 调试 JavaScript 计时事件

转载 作者:行者123 更新时间:2023-11-28 21:22:41 25 4
gpt4 key购买 nike

我在使用此 JavaScript 脚本时遇到问题。我尝试了很多方法来让它发挥作用。目前那里的警报是为了调试目的,并且似乎没有发生。

请帮忙?

function checkTime(this_time){
var the_string = "checkTime("+this_time+")";
var now = ((new Date()).getTime());
if(parseInt(now) >= parseInt(this_time)){
document.write("TIMEUP!");
}
alert(now);
alert(this_time);
var t = setTimeout(the_string,300);
}

var the_time = (((new Date()).getTime())+19000);
var the_string = "checkTime("+the_time+")";
var t = setTimeout(the_string,300);

谢谢

愿意。

最佳答案

您似乎在寻找倒计时?
请参阅this fiddle 。代码简化为:

var bench  = 19000 + new Date().getTime(),
timer = setInterval(
function(){
checkTime(bench);
}
, 1000
);

function checkTime(this_time){
var check = new Date - this_time;
if(check>=0){
alert('time\'s up!');
clearInterval(timer);
}
}

关于javascript - 调试 JavaScript 计时事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5857018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com