更新时间:2022-11-03 10:08:33
使用document.onkeypress
(或兄弟姐妹onkeydown
和onkeyup
):
Use document.onkeypress
(or the siblings onkeydown
and onkeyup
):
document.onkeypress = function (event) { ... };
jQuery 为这些事件提供的服务,例如
jQuery offers for these events, e.g.,
$(document).keypress (function (event) { ... });
这将捕获您网站上的所有个按键事件.在函数内部,您可以使用event.keyCode
获取所按键的数字代码.请注意,存在一些浏览器不兼容性,尤其是与keypress
事件有关.有关FF如何处理的信息,请参见 developer.mozilla.com .
This will catch all key press events on your site. Inside the function you can get the numeric code of the pressed key with event.keyCode
. Be aware, that there are some browser incompatibilities, especially with the keypress
event. See developer.mozilla.com for how FF handles it.
干杯