jQuery将keyup绑定到firefox中的主体 [英] jquery bind keyup to body in firefox

查看:87
本文介绍了jQuery将keyup绑定到firefox中的主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将jquery中的keyup函数绑定到主体,该主体在每个浏览器中均有效 除了Firefox

i m binding keyup function in jquery to body which works in every browser except firefox

代码:-

 $('body').bind('keyup', function(e) {
    //alert ( e.which );
    alert('testing');

});

我该怎么做才能使用Firefox.它根本不响应

how do i do it for firefox. it does not responds at all

谢谢

推荐答案

将事件绑定到document:

$(document).bind('keyup', function(e) {
    alert('testing');
});

您几乎可以使任何节点都接收键盘事件.在现代"浏览器中,您可以设置tabIndex.之后,该事件将成为焦点.

You can make almost any node receive keyboard events. In "modern" browsers, you can setup a tabIndex. After that the event is focusable.

$(document.body).attr('tabIndex', 1).bind('keyup', function(e) {
    alert('testing');
});

这篇关于jQuery将keyup绑定到firefox中的主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆