I thought this would be answered somewhere on Stack Overflow, but I can't find it.
(我以为可以在Stack Overflow的某处得到答案,但我找不到。)
If I'm listening for a keypress event, should I be using .keyCode
or .which
to determine if the Enter key was pressed?
(如果我在听一个按键事件,我应该使用.keyCode
或.which
,以确定是否被按下回车键?)
I've always done something like the following:
(我一直都做以下事情:)
$("#someid").keypress(function(e) {
if (e.keyCode === 13) {
e.preventDefault();
// do something
}
});
But I'm seeing examples that use .which
instead of .keyCode
.
(但我看到的例子是使用.which
,而不是.keyCode
。)
(有什么不同?)
Is one more cross-browser friendly than the other?(一个跨浏览器比另一个浏览器更友好吗?)
ask by ScottE translate from so