[英]How to get elements with the different value of the same attribute in javascript or jquery?
I need to find elements with the different value of the same attribute... This works-> $data.find("div[data-alpha='1']");
我需要找到具有相同属性的不同值的元素...这有效-> $data.find("div[data-alpha='1']");
But i need something like this-> $data.find('div[data-alpha='1']' + 'div[data-alpha='2']
' .... So i want to find all elements which have the,,data-alpha" atribute 1 or 2. Anyone have an idea how to do that? Thanks for all answers! Cheers!但我需要这样的东西-> $data.find('div[data-alpha='1']' + 'div[data-alpha='2']
' .... 所以我想找到所有元素有,,data-alpha”属性 1 或 2。任何人都知道如何做到这一点?感谢所有答案!干杯!
Use the multiple-selector
[docs] .使用multiple-selector
[docs] 。
$data.find("div[data-alpha='1'], div[data-alpha='2']")
This allows you to accumulate the results of different selectors by joining the selectors with a comma into a single selector.这允许您通过用逗号将选择器连接到单个选择器中来累积不同选择器的结果。
Try the add() method ( http://api.jquery.com/add/ ).尝试 add() 方法( http://api.jquery.com/add/ )。
If you want to find all elements with the data-alpha attribute use如果要查找具有 data-alpha 属性的所有元素,请使用
$data.find([data-alpha])
If you need elements with specific values, use:如果您需要具有特定值的元素,请使用:
$data.find([data-alpha=x],[data-alpha=y])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.