jQuery:我如何监听一般键盘输入? [英] jQuery: How do I listen for general keyboard input?
本文介绍了jQuery:我如何监听一般键盘输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个网站,在加载页面后,需要监听特定的键盘字符串。
I'm building a site that after the page is loaded, needs to listen for a particular keyboard string.
我感兴趣的事件实际上是一个扫描对象的扫描仪,但它作为键盘输入提供给网站,格式为 ~XXX 〜
。
The event I am interested in is actually a scanner scanning an object, but it presents to the site as keyboard input, of the form ~XXX~
.
我看到jQuery有一个你可以绑定的 keypress()
事件一个特定的对象。
I see jQuery has a keypress()
event that you can bind to a particular object.
但是如何在 $(文件).ready
之后听一般的键盘输入?
But how can I listen for general keyboard input, after $(document).ready
?
推荐答案
试试这个:
$(function() {
$(window).keypress(function(e) {
var key = e.which;
//do stuff with "key" here...
});
});
在 jsFiddle
这篇关于jQuery:我如何监听一般键盘输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文