如何合并两个jQuery选择器? [英] How can I combine two jQuery selectors?

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

问题描述

我有以下选择器:

$('#menu a[href^="/C"]').live('click', function (event) { } )
$('#menu a[href^="/T"]').live('click', function (event) { } )

一个选择以/C开头的href,另一个选择/T

One selects href that starts with /C and the other /T

有没有办法将它们结合起来?

Is there a way that I can combine these?

推荐答案

您提供的选择器是完全相同的,但总的来说,您要做的就是用逗号分隔两个选择器,如下所示:

The selectors you gave were exactly the same, but in general all you have to do is comma delimit the two selectors like the following:

$('#firstSelector, #secondSelector');

有关更多信息,请访问多个选择器

For more information check out the jquery site on mutiple selectors

这应该是您想要的:

$('#menu a[href^="/C"], #menu a[href^="/T"]').live('click',function(e){});

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

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