How to know the reason of blur?

后端 未结 2 1574
既然无缘
既然无缘 2021-02-07 03:02

How can I know which event caused a blur event in jQuery?

Blur event triggered using click or tab etc. How can I know this blur event is due to click or tab

2条回答
  •  渐次进展
    2021-02-07 03:17

    If you are trying to do two different things depending on which method was used, bind handlers to listen for .click() and .keyup(), then check for the keycode

    var k = (window.event) ? event.keyCode : e.keyCode;
    

    Or something on the order of this if you need

    $(document).bind("click keyup", function(){
       //check keycode
       var e = (window.event);
       var k = (e)?event.keyCode:e.keyCode;
       if(k==9){
          //tab code
       }else if(e.type=='click'){
          //click code
       }
    
    });
    

提交回复
热议问题