jQuery: Find all the visible required fields

后端 未结 1 1196
孤独总比滥情好
孤独总比滥情好 2020-12-29 21:10

I am trying to find all the fields with required attribute and they should be visible too. Because page can have hidden required fields too. Here i

1条回答
  •  一向
    一向 (楼主)
    2020-12-29 21:37

    If you want to find input, textarea,or select elements that have the attribute required and are visible use the has attribute selector:

    $('input,textarea,select').filter('[required]:visible')
    

    or

    $(':input[required]:visible')//might be little costlier
    

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