(jQuery) Select 元素到 TD 并过滤仅包含数字的值
(jQuery) Select element into TD and filter values with only digits
我有一个 table 有很多像这样的 td“.numbers”:
<tr><td class="numbers">12345</td></tr>
<tr><td class="numbers">6789</td></tr>
<tr><td class="numbers">123%</td></tr>
我只需要 select 没有“%”和其他字符的 TD 值。
注意: 我无法删除 class "numbers" 因为是自动生成的。
这不起作用:
$.each($(".numbers"), function( index, value ) {
if ($(".numbers").text().indexOf("%")<0) {
//do stuff
}
}
我如何 select td 值并使用 indexOf 进行过滤?
谢谢!
获取其中包含数值的 td 元素:
$(".numbers").filter(function(){
return $.isNumeric($(this).text());
});
我有一个 table 有很多像这样的 td“.numbers”:
<tr><td class="numbers">12345</td></tr>
<tr><td class="numbers">6789</td></tr>
<tr><td class="numbers">123%</td></tr>
我只需要 select 没有“%”和其他字符的 TD 值。
注意: 我无法删除 class "numbers" 因为是自动生成的。
这不起作用:
$.each($(".numbers"), function( index, value ) {
if ($(".numbers").text().indexOf("%")<0) {
//do stuff
}
}
我如何 select td 值并使用 indexOf 进行过滤? 谢谢!
获取其中包含数值的 td 元素:
$(".numbers").filter(function(){
return $.isNumeric($(this).text());
});