Find if a textbox is currently selected

后端 未结 5 1212
栀梦
栀梦 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 11:36

    Ok, just figured it out. Here's what I did:

    function checkFocus() {
    
      if ($(document.activeElement).attr("type") == "text" || $(document.activeElement).attr("type") == "textarea") {
    
      //Something's selected
    
      return true;
    
     }
    
    }
    

提交回复
热议问题