[英].querySelectorAll how to take only elements with all attributes
If i have that string:` 如果我有那个字符串:
document.querySelectorAll("[data-name=" + CSS.escape(variable) + "]","[class='nameclass']");
It takes all elements with the first attribute and all elements with the second attribute. 它采用具有第一个属性的所有元素以及具有第二个属性的所有元素。
How I have to do for take only elements with each attributes? 我该如何只取每个属性的元素?
It seems you are looking for this selector: 看来您正在寻找这个选择器:
document.querySelectorAll(".nameclass[data-name=" + CSS.escape(variable) + "]");
Please note that I have used .nameclass
as a class selector which differs from [class=nameclass]
. 请注意,我已经将
.nameclass
用作与[class=nameclass]
不同的类选择器。 The first one selects the elements that one of their classes is nameclass
and the second one selects elements that have just nameclass
class attribute. 第一个选择其类之一是
nameclass
的元素,第二个选择仅具有nameclass
类属性的元素。
If the elements that have just nameclass
class attribute should be selected, the selector should be: 如果应该选择仅具有
nameclass
class属性的元素,则选择器应为:
"[class=nameclass][data-name=" + CSS.escape(variable) + "]"
I've resolved with that: 我已经解决了:
document.querySelectorAll("[data-name=" + CSS.escape(item) + "][class='placeholder matched']");
removing the , 删除,
Thanks for all response 感谢您的所有回复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.