Find if a textbox is currently selected

后端 未结 5 1152
栀梦
栀梦 2021-01-12 11:08

How would I find if a textbox (or textarea) currently is in focus? I don\'t care to know which one it is, I just need to know if one is in focus (has the cursor in it). How

5条回答
  •  心在旅途
    2021-01-12 11:36

    Since you have found document.activeElement, you can check its nodeName.

    if (document.activeElement.nodeName == 'TEXTAREA' || document.activeElement.nodeName == 'INPUT') {
        // ....
    }
    

    Something like that.

提交回复
热议问题