javascript - (jQuery) 将元素选择到 TD 中并过滤仅包含数字的值

标签 javascript jquery html indexof

我有一张表,上面有很多 td ".numbers",如下所示:

<tr><td class="numbers">12345</td></tr>
<tr><td class="numbers">6789</td></tr>
<tr><td class="numbers">123%</td></tr>

我只需要选择没有“%”和其他字符的 TD 值。
注意:我无法删除类“numbers”,因为它是自动生成的。

这是行不通的:

$.each($(".numbers"), function( index, value ) {
    if ($(".numbers").text().indexOf("%")<0) {
    //do stuff
    }
}

我如何选择 td 值并使用 indexOf 进行过滤? 谢谢!

最佳答案

获取其中具有数值的 td 元素:

$(".numbers").filter(function(){
     return $.isNumeric($(this).text());  
});

关于javascript - (jQuery) 将元素选择到 TD 中并过滤仅包含数字的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30305666/

相关文章:

html - 如何使用 li 和 ul 标签从 Selenium 的下拉列表中选择值?

jquery - 调整菜单大小后页面内容消失

javascript - hashchange 事件未在简单 spa 中使用 jquery 触发

javascript - jquery 进度条不显示

javascript - ng-repeat 和 ng-scrollbar 不能一起工作

javascript - ajax成功响应更改为@html.raw

javascript - IE8 中 HTML 字符串上的 jQuery .find()

JavaScript 错误 : Expected 'html' and instead saw 'script'

javascript - 通过标签输入下拉搜索

html - 为什么我的网页在文本行之间有巨大的空间?