[英]Loop elements and check if class exists javascript
I have 3 select option. 我有3个选择选项。 I can get them in this way: 我可以这样获得它们:
var theSelect = $("#id_"+portletId+"_ .selectpicker");
and the results is: 结果是:
0:select#_Name_zeroid.form-control.selectpicker.completed
1:select#_Name_firstid.form-control.selectpicker.completed
2:select#_Name_secondid.form-control.selectpicker
as you can see 2 of these select have the attributes completed
. 如您所见,其中2个选择的属性completed
。 How can I loop these and get a simple console.log()
if the attribute completed
exists? 如果属性completed
存在,如何循环这些并获取简单的console.log()
?
You can use the classList
DOM attribute which has a contains
method which takes a string and returns a boolean. 您可以使用classList
DOM属性,该属性具有一个contains
方法,该方法接受一个字符串并返回一个布尔值。
Or you can use jQuery 或者您可以使用jQuery
Native 本地人
document.querySelectorAll(".selectpicker").forEach(node => node.classList.contains("completed"));
jQuery jQuery的
// filter the results
const theSelect = $("#id_"+portletId+"_ .selectpicker").filter(".completed");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.