Javascript 窗口。位置是否受退出键影响?

Javascript 窗口。位置是否受退出键影响?,javascript,Javascript,我有一个计时器来刷新页面,它正在工作: updateCountdown = function() { if (Variables.Seconds == Infinity) { } else if (Variables.Seconds == 0) { $countdown.text('Bam!'); window.location.replace(Variables.PageName); } else { $countdown

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

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显示“砰!”,但是页面不会像变量出现时一样刷新。秒通常会递减到0。

您可能需要执行
返回false;取消转义的默认操作

   document.onkeydown=function(e) {

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

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

您可能需要执行
返回false;取消转义的默认操作

   document.onkeydown=function(e) {

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

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

e.preventDefault()!我在想什么@菲利普斯我通过艰苦的方式学会了这一点(在类似的问题上浪费了几天)!我在想什么@菲利普斯恩:我从中学到了这一点(在类似问题上浪费了几天)。