gpt4 book ai didi

javascript - window.location 受转义键影响吗?

转载 作者:行者123 更新时间:2023-11-28 16:31:38 24 4
gpt4 key购买 nike

我有一个刷新页面的计时器,它正在工作:

updateCountdown = function() {
if (Variables.Seconds == Infinity) {
} else if (Variables.Seconds == 0) {
$countdown.text('Bam!');
window.location.replace(Variables.PageName);
} else {
$countdown.text(Variables.Seconds--);
setTimeout(updateCountdown, 1000);
}
};

然后我有这个:

document.onkeydown=function(e) {

if (e.which==27) {
Variables.Seconds = 0;
updateCountdown();
}
};

当我按 escape 时,$countdown.text 会显示“Bam!”,但页面不会像 Variables.Seconds 通常递减到 0 时那样刷新。

最佳答案

在调用 updateCountdown(); 后,您可能需要执行 return false;取消 Escape 的默认操作。

   document.onkeydown=function(e) {

if (e.which==27) {
Variables.Seconds = 0;
updateCountdown();
return false;
}
};

如果您正在使用其他 javascript 库 this post可能会有所帮助。

关于javascript - window.location 受转义键影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5681257/

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