【发布时间】:2010-08-12 10:52:36
【问题描述】:
任何第一次按键后都会有轻微的停顿。 这是日志:
[00.000ms] keypress -- 第一次按键 [496.00ms] keypress -- 496 ms 后的第二次按键 [39.000ms] 按键——大约 20-40 毫秒后每隔一次按键。 [41.000ms] 按键 [21.000ms] 按键 [39.000ms] 按键 ...所以在第一次按键后会有半秒的暂停,其余的会在 20-40 毫秒后触发。
这是获取按键的代码:
// If we're using the webkit engine, capture the keydowns
if(navigator.userAgent.indexOf("WebKit") != -1){
window.onkeydown = onKeyPress;
} else{
// If we're using gecko, capture the keypress
if(navigator.userAgent.indexOf("Gecko") != -1){
window.onkeypress = onKeyPress;
}
}
onKeyPress 函数执行的第一件事是调试输出(上面的日志中的那个)
有人知道为什么会有停顿吗? 就像在 Windows 或 Linux 上一样; Firefox 或 Chrome。
【问题讨论】:
标签: javascript keypress