javascript - 检查字符串中的特定字符

标签 javascript jquery

如何检查元素中的特定字符?

<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/

相关文章:

php - 使用 jquery ajax 将 javascript 对象转换为 php

javascript - 使用正则表达式分别拆分 = 、 == 和 ===

javascript - 如何让按钮到javascript中的下一行

jquery - tablesorter JQuery 插件不使用 IE 11 和显示 block 进行排序

javascript - backbone.js 根据另一个 View 中的事件更新一个 View ?

javascript - 生成随机的绿色阴影

javascript - Three.js 正交相机 : Zoom All

javascript - 如何使用 jquery 脚本使向上滑动默认打开?

Click for CSS 上的 JQuery 不起作用

javascript - 将鼠标悬停在一个跨度上,然后通过添加和删除类来更改该跨度以及另一个跨度的背景颜色