合并两个jQuery选择 [英] Merging two jQuery selections
本文介绍了合并两个jQuery选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var _sel1 = $('.red');
var _sel2 = $('.yellow');
如何在不使用其他选择器的情况下将它们合并为一个?
How can I merge them into one, without using different selectors?
// I don't want to do it this way
var _sel3=$('.red,.yellow') or $('.red').add('.yellow');
推荐答案
使用 add()
:
var _sel3 = _sel1.add(_sel2);
这篇关于合并两个jQuery选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文