我的每个列表元素都有属性,例如:data-content="1 000 PLN"
。
如果用户写data-content
或1 000
,1000
或{{1},我想写一个与此25 000 000
匹配的RegExp查询无关紧要}?
我想在JavaScript上使用它。
答案 0 :(得分:0)
无需使用正则表达式,只需使用document.querySelectorAll。
document.querySelectorAll("[data-content]");
这将为您提供具有data-content属性的元素列表。
然后,您可以迭代元素以获取属性值
Array.prototype.forEach.call(document.querySelectorAll("[data-content]"), function( divChild ){
console.log(divChild.getAttribute("data-content"));
});