如何合并两个jQuery结果 [英] How to combine two jQuery results

查看:132
本文介绍了如何合并两个jQuery结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何合并两个jQuery搜索结果?例如:

How do you combine two jQuery search results? eg:

var $allFoos = $('.foo'),
    $allBars = $('.bar')
    $allFoosAndBars = $allFoos + $allBars
;

很显然,我刚刚写完了最后一行,但我希望它能使我的意思清楚一点.为了清楚起见,该示例已大大简化,它可能是我在谈论的任意集,因此$('.foo, .bar')不是我想要的 .

Obviously, I just made up that last line, but I hope it makes it sorta clear what I mean. To be clear, the example is greatly simplified, and it could be any arbitrary sets i'm talking about, so $('.foo, .bar') is not what I'm after.

推荐答案

您可以使用 add();

var $foos = $('.foo');

var $foosAndBars = $foos.add('.bar');

var $allFoosAndBars = $allFoos.add($allBars);

这篇关于如何合并两个jQuery结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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