jQuery selector for selecting an input field with a class

前端 未结 4 1384
一整个雨季
一整个雨季 2021-02-05 17:05

I have



&l         


        
相关标签:
4条回答
  • 2021-02-05 17:50
    $(':input.required[type="text"]')
    

    EDIT:

    This will be slightly faster:

    $('input.required[type="text"]')
    

    Note:

    :input will get all form elements (<select>, <textarea>, etc.)

    input will only get <input> elements, and is slightly faster.

    0 讨论(0)
  • 2021-02-05 17:50
    $(':input[type="text"][class="required"]')
    

    That should work

    http://jsfiddle.net/ck8wt/

    Edit

    lol ... I couldn't see the forest through the trees. :P I'll leave mine up too though just as an illustration of how many ways this can be done. XD

    0 讨论(0)
  • 2021-02-05 17:57
    $('.required:input[type="text"]')
    

    (also $('input.required[type="text"]'))

    0 讨论(0)
  • 2021-02-05 17:57

    If you just add the class to your selector, it should do what you are looking for.

    $('.required:input[type="text"]')
    
    0 讨论(0)
提交回复
热议问题