【问题标题】:(jQuery) Select element into TD and filter values with only digits(jQuery) 将元素选择到 TD 中并过滤仅包含数字的值
【发布时间】:2015-05-18 14:18:32
【问题描述】:

我有一张表,里面有很多像这样的 td ".numbers":

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

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

这不起作用:

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

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

【问题讨论】:

    标签: javascript jquery html indexof


    【解决方案1】:

    用于获取其中包含数值的 td 元素:

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

    【讨论】:

    • 这是简单字符的一个很好的解决方案,但我想问题应该是select TD with only numeric chars,遵循有问题的声明:values without "%" and other chars
    • @A.Wolff:感谢您的指出。在没有 % 的情况下感到困惑 :)
    猜你喜欢
    • 2017-04-23
    • 2016-10-10
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多