简体   繁体   English

.querySelectorAll如何仅采用具有所有属性的元素

[英].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.

相关问题 如何删除通过 Ajax 加载到 DOM 中的 querySelectorAll 匹配的所有元素的特定属性? (使用纯 JavaScript) - How to remove specific attributes of all elements matched by querySelectorAll which were loaded into DOM via Ajax? (with plain JavaScript) Javascript querySelectorAll,如何只匹配顶级元素? - Javascript querySelectorAll, how to match with only top elements? querySelectorAll不选择所有元素 - querySelectorAll not selecting all elements 使用querySelectorAll获取具有该类名称的所有元素,而不仅仅是第一个 - Using querySelectorAll to get ALL elements with that class name, not only the first querySelectorAll 没有选择所有选定的元素 - querySelectorAll not selecting all the selected elements querySelectorAll 不返回 DOM 中的所有元素 - querySelectorAll not returning all elements in DOM querySelectorAll - 如何只获取某个div中的元素 - querySelectorAll - How to only get elements within a certain div 如何仅将 querySelectorAll 用于具有特定子元素的元素? - How to use querySelectorAll only for elements that have a specific child element? 如何仅对具有特定属性集的元素使用 querySelectorAll? - How to use querySelectorAll only for elements that have a specific attribute set? 如何使querySelectorAll仅从当前元素的子元素中选择 - How to make querySelectorAll select only from child elements of the current element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM