jQuery alternative for document.activeElement

后端 未结 5 1426
青春惊慌失措
青春惊慌失措 2020-12-30 01:50

What I wanted to do is figure out whenever the user is engaged with an INPUT or TEXTAREA element and set a variable flag to true... and set that flag to false immediately af

5条回答
  •  粉色の甜心
    2020-12-30 02:01

    You want the focus and blur event handlers. For example...

    var inFocus = false;
    $('input, textarea').focus(function() {
      inFocus = true;
    });
    
    $('input, textarea').blur(function() {
      inFocus = false;
    });
    

    I'm pretty sure that a comma will get you input OR textarea, but you get the idea if that doesn't pan out

提交回复
热议问题