如何在多个属性值上选择元素 [英] How do I select elements on multiple attribute values

查看:82
本文介绍了如何在多个属性值上选择元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery,可以轻松选择具有给定属性值的元素.

With jQuery, it is easy to select elements with a given attribute value.

例如:

var elements = $('div[attr1="value1"]');

但是如何选择多个属性(例如attr1 = value1 attr2 = value2)?

But how do I select on multiple attributes (e.g., attr1 = value1 and attr2 = value2)?

推荐答案

由于jquery使用CSS选择器,如CSS规范所定义,具有多个条件的选择器将如下所示:

Since jquery uses CSS selectors, as defined by the CSS specification a selector with multiple conditions will look like:

$('div[attr1="value1"][attr2="value2"]')

有关更多参考,请参见CSS规范: http://www. w3.org/TR/CSS2/selector.html#matching-attrs

see the CSS spec for further reference: http://www.w3.org/TR/CSS2/selector.html#matching-attrs

这篇关于如何在多个属性值上选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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