您可以在jQuery选择器上执行“与"操作以定位多个按钮吗? [英] Can you do an 'AND' on a jQuery selector to target multiple buttons?

查看:96
本文介绍了您可以在jQuery选择器上执行“与"操作以定位多个按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种想要使用相同代码块的按钮.除了创建两个事件处理程序外,还可以通过执行以下操作来引用按钮:

I have two types of buttons that I want to use the same code block. Rather than create two event handlers is it possible to reference the buttons by doing something like this:

$(".lb",".da")

我尝试了具体示例,但它没有用,但希望它能使您对我的目标有所了解.

I tried the specific example and it doesn't work but hopefully it'll give you an idea for what I'm aiming at doing.

推荐答案

是的,jQuery的工作原理类似于CSS:

Yes, jQuery works just like CSS:

$(".lb, .da")

您可以使用逗号来使用多个选择器,或者使用>来选择直接后代:

You can use commas to use multiple selectors, or a > to select a direct descendant:

$("#parent > ul")

还有更多,但是 W3C网站上的此页面将它们详细地描述了清楚地.请查看第2节中的示例表.

There are many more, but this page at the W3C site details them pretty clearly. Check out Section 2 for a table with examples.

这篇关于您可以在jQuery选择器上执行“与"操作以定位多个按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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