且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有焦点的情况下使用javascript读取html页面中的输入

更新时间:2022-11-03 10:08:33

使用document.onkeypress(或兄弟姐妹onkeydownonkeyup):

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.

干杯