[英]JQuery how to apply on list of selectors
I'm newby with Jquery and I'm trying to find out how to apply on a list of selectors. 我是Jquery的新人,我试图找出如何应用于选择器列表。 Sometimes I need to be able to differentiate c1,c2 and c3. 有时我需要能够区分c1,c2和c3。 For others I'd like to apply to the three something 对于其他人,我想适用于这三个东西
$c1 = $div.find('#widget-row-c').sortedList();
$c2 = $div.find('#widget-col-c').sortedList();
$c2 = $div.find('#widget-filter-c').sortedList();
$containers = ? // as $c1 + $c2 + $c3
$c1.doSomethingForC1(); // only for c1
$containers.doSomethingForC1C2C3(); // for all three
How it's possible to do this ? 如何做到这一点?
只需用逗号分隔选择器
var containers = $('#widget-row-c, #widget-col-c, #widget-filter-c');
Try $containers = $c1.add($c2).add($c3);
尝试$containers = $c1.add($c2).add($c3);
. 。
I would consider using both id
and class
selectors for this. 我会考虑同时使用id
和class
选择器。 If all elements have, say, a widget-container
class you could do: 例如,如果所有元素都有widget-container
类,则可以执行以下操作:
$c1 = $div.find('#widget-row-c').sortedList();
$c2 = $div.find('#widget-col-c').sortedList();
$c3 = $div.find('#widget-filter-c').sortedList();
$containers = $('.widget-container');
$c1.doSomethingForC1(); // only for c1
$containers.doSomethingForC1C2C3(); // for all three
Basically, if you know you're going to want to select a single thing, grab it by Id
. 基本上,如果您知道要选择一个选项,请通过Id
进行选择。 Otherwise, grab all of the same kind by selecting by class
否则,请按class
进行选择,以获取相同种类的物品
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.