如何检查元素中的特定字符?
<div>N0180/RIB</div>
<div>N0180918</div>
<div>N0180</div>
**(I want to target <div>N0180</div> this element)**
我尝试使用 :contains("N0180")
和 .substring
方法。但它是针对所有三个要素的。
最佳答案
根据 :contains()
文档:
The matching text can appear directly within the selected element, in any of that element's descendants, or a combination thereof. As with attribute value selectors, text inside the parentheses of :contains() can be written as a bare word or surrounded by quotation marks. The text must have matching case to be selected.
您可以使用 .filter() 更具体的比较:
$('div').filter(function(){
return $(this).text().trim() === "N0180";
})
关于javascript - 检查字符串中的特定字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36418947/