jquery bind keyup to body in firefox

2020-02-11 01:22发布

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

the code: -

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

});

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

thanks

1条回答
地球回转人心会变
2楼-- · 2020-02-11 01:52

bind the event to the document instead:

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

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');
});
查看更多
登录 后发表回答