Is there a 'has focus' in JavaScript (or jQuery)?

后端 未结 10 1272
北恋
北恋 2020-11-30 00:36

Is there something I can do like this (perhap via a plugin)

if ( ! $(\'form#contact input]\').hasFocus()) {
  $(\'form#contact input:first]\').focus();
}
         


        
10条回答
  •  一个人的身影
    2020-11-30 00:56

    I know this is an old question, but may be my solution will help someone :)

    since this didnt worked for me:

    if ($(this)!=$(document.activeElement)) { ... }
    

    ..were "this" is returned from blur function. So i did this:

    if ($(document.activeElement).attr("class") != "input_textbox"){ ... }
    

提交回复
热议问题