在jQuery中串联选择器? [英] Concatenate selector in jQuery?

查看:74
本文介绍了在jQuery中串联选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定"concatenate"是否是正确的术语,但是类似这样:

I am not sure if "concatenate" is the correct term for it, but something like this:

$("#a").$("#b").$("#c").$("#d").click();   // click on all of them

基本上,我有很多东西,但是我不能给他们上课.

Basically I have a long list of stuff but I can't apply a class to them.

推荐答案

作为 CSS ,您可以使用逗号分隔多个选择器:

As in CSS, you can use a comma to separate multiple selectors:

$("#a, #b, #c, #d").click();

请注意,这些不一定是同一类型的选择器.例如:

Note that these do not have to be the same kind of selector. For example:

// Click the menu, all spans in all .foo, and paragraphs after headers
$("#menu, div.foo span, h1 + p").click();

此外,如果您已经拥有 jQuery对象,则可以 add() 这样的集合:

Also, if you already have the jQuery objects, you can add() the sets like so:

var a = $('#a'), b = $('#b'), c = $('#c');
var all = a.add(b).add(c);

这篇关于在jQuery中串联选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆