如何使用多个jquery对象变量作为选择器? [英] How to use multiple jquery object variables as selectors?
本文介绍了如何使用多个jquery对象变量作为选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中,可以选择多个元素,例如:
In jQuery, selecting more than one element can be done like this:
$("#id1,#id2").show();
但是当我有两个jQuery对象时,我似乎无法使用变量本身选择多个对象.例如:
But when I have two jQuery objects, I don't seem to be able to select more than one using the variables themselves. For example:
var jqId1 = $("#id1");
var jqId2 = $("#id2");
$(jqId1).show(); // This works.
$(jqId1,jqId2).show(); // This only shows jqId1.
请参阅jsFiddle: http://jsfiddle.net/jr9Q2/
See jsFiddle: http://jsfiddle.net/jr9Q2/
还有另一种方法可以将多个jq变量指定为选择器吗?
Is there another way of specifying multiple jq variables as selectors?
推荐答案
您可以使用添加:
jqId1.add(jqId2).show();
但是不要为了避免查询"#id1,#id2"
而使代码过于复杂:此选择器依赖于getElementById
并且非常快.
But don't make your code too complex just to avoid querying "#id1,#id2"
: this selector relies on getElementById
and is very fast.
这篇关于如何使用多个jquery对象变量作为选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文