简体   繁体   English

如何在jQuery中使用过滤器链接多个选择器?

[英]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)'. 输入多个'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 : 你试过.not()方法了吗?

$('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.) (注意':input'选择器除了输入,select和textarea元素之外还选择按钮元素。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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