将两个选择器与一个jQuery对象组合在一起 [英] Combine two selectors with one jQuery object

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

问题描述

我有两个带ID的div: #addNew_tab #sendCom_tab

I '点击这些触发相同的jQuery click()函数。



我在想什么例如:

  $(#addNew_tab,#sendCom_tab)。click(function(){
/ /做东西
});

但不起作用。

解决方案

  $(#addNew_tab,#sendCom_tab)。click(function(){
// do stuff
} );

更改:

  $(#addNew_tab,#sendCom_tab)

/ p>

  $(#addNew_tab,#sendCom_tab)






选择器内的逗号(a,b)表示第一个加上第二个;就像使用CSS选择器
一样(这是一个CSS选择器...)

lockquote
jQuery选择器)



描述:接受一个包含 CSS选择器的字符串,然后用它来匹配一组元素。 p>

等于:

  $ (#addNew_tab)。add(#sendCom_tab)... 


I have two divs with id's: #addNew_tab and #sendCom_tab.
I'd like clicking on either of these to trigger the same jQuery click() function.

I was thinking something like:

$("#addNew_tab", "#sendCom_tab").click(function(){
      //do stuff
});

but that doesn't work.

解决方案

$("#addNew_tab, #sendCom_tab").click(function(){
      //do stuff
});

Changed from:

$("#addNew_tab", "#sendCom_tab")

To:

$("#addNew_tab, #sendCom_tab")


comma inside the selector("a, b") means the first plus the second; Just like with CSS selectors
(Well, it's a CSS selector...)

jQuery(selector)

Description: Accepts a string containing a CSS selector which is then used to match a set of elements.

It's equal to:

$("#addNew_tab").add("#sendCom_tab")...

这篇关于将两个选择器与一个jQuery对象组合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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