jquery, set focus on the first enabled input or select or textarea on the page

后端 未结 4 1582
甜味超标
甜味超标 2020-12-29 19:23

It\'s fairly straightforward. I want to set focus to the first enabled and not hidden control on the page.

For a textbox, I have

$(\"input[type=\'t         


        
相关标签:
4条回答
  • 2020-12-29 20:09
    $(':input:enabled:visible:first').focus();
    
    0 讨论(0)
  • 2020-12-29 20:10

    Try this:

    $("input[type='text']:enabled","another selector","another selector").first().focus();
    
    0 讨论(0)
  • 2020-12-29 20:26

    As an extension of Jordan's answer

    $(':input:enabled:visible:not([readonly]):first').focus();
    

    This one also excludes readonly inputs

    0 讨论(0)
  • 2020-12-29 20:28

    This is a little more comprehensive:

    $('form :input:text:visible:not(input[class*=filter]):first').focus();
    

    Lamen: Focus the cursor in the first text input in a form that is visible, but if it use the class named "filter", ignore it!

    0 讨论(0)
提交回复
热议问题