简体   繁体   中英

How do I chain multiple selectors with filters in jQuery?

I'm trying to select multiple elements which do not have the attribute 'disabled' but I'm not sure if there's an easier way to type this:

$('input:not(:disabled), select:not(:disabled), textarea:not(:disabled)')

It seems a little wasteful to be typing multiple 'not(:disabled)'.

This should work:

$('input, select, textarea').filter(':enabled');

Or if you want to get really short:

$(':input:enabled')

您可以使用:input选择器和.not()方法

$(':input').not(':disabled')

Have you tried the .not() method :

$('input, select, textarea').not(':disabled')

Which can be further simplified to:

$(':input').not(':disabled')

(Note that the ':input' selector selects button elements in addition to input, select and textarea elements.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM