jquery bind keyup to body in firefox

前端 未结 1 1492
甜味超标
甜味超标 2020-12-17 17:45

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

the code: -

 $(\'body\').bind(\'keyup\', function(e) {
    /         


        
相关标签:
1条回答
  • 2020-12-17 18:32

    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');
    });
    
    0 讨论(0)
提交回复
热议问题