gpt4 book ai didi

javascript - Esc 键在 Firefox 中无法识别

转载 作者:行者123 更新时间:2023-12-02 07:45:41 26 4
gpt4 key购买 nike

由于某些原因,这个脚本在 Firefox 中不工作:

document.onkeydown=function keypress(e) {
if (e.keyCode == 27) {
window.location = "/edit"
};
};

它在 Chrome 中运行良好,但由于某些原因在 Firefox 中无法运行。

基本上,它的作用是在您按下转义键时加载 /edit 页面。

最佳答案

使用:

document.onkeydown=function keypress(e) {
e=(e||window.event);
if (e.keyCode == 27) {
try{e.preventDefault();}//Non-IE
catch(x){e.returnValue=false;}//IE
window.location = "/edit";
};
}

ESC 的默认操作是停止加载页面,
所以你必须防止这种行为,否则你不能改变位置。

fiddle :http://jsfiddle.net/doktormolle/CsqgE/ (在使用 ESC 之前先点击进入结果框)

但是,你真的应该使用另一个 key 。
用户希望如果他使用 ESC 就停止当前页面的加载,而不是其他。

关于javascript - Esc 键在 Firefox 中无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7218581/

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