在tr中为td的每个函数Jquery(Jquery each function for td in tr)

编程入门 行业动态 更新时间:2024-10-24 18:24:19
在tr中为td的每个函数Jquery(Jquery each function for td in tr)

我基本上想找到tbody中每个tr的每秒eq(1)td的val ...

var distancefrom = x;
var distanceto = y;

$("#village_troup_list tbody tr").each(function () 
{
    var allo = $("#village_troup_list tbody tr").find('td').eq(1).val();
});
 

... 接着:

if (distancefrom <= [theValueImGetting] <= distanceto) 
{
    // run something for the tr this td is in
}
 

我试过$(this) ,但它没有做任何事情,所以我猜这不是正确的方法。

我怎么能以一种干净的方式做到这一点?

I basically want to find every second eq(1) td's val for each tr in the tbody ...

var distancefrom = x;
var distanceto = y;

$("#village_troup_list tbody tr").each(function () 
{
    var allo = $("#village_troup_list tbody tr").find('td').eq(1).val();
});
 

... and then:

if (distancefrom <= [theValueImGetting] <= distanceto) 
{
    // run something for the tr this td is in
}
 

I tried $(this), but it didn't do anything, so I'm guessing that's not the right approach.

How could I do this in a neat manner?

最满意答案

var trs = $('#village_troup_list tr td:nth-of-type(2)').map(function() { var val = $(this).text(); if(val >= distancefrom && val <= distanceto) return $(this).parent(); }); trs.each(function(i, tr) { // run something for the tr which second td element's value meets the criteria }); var trs = $('#village_troup_list tr td:nth-of-type(2)').map(function() { var val = $(this).text(); if(val >= distancefrom && val <= distanceto) return $(this).parent(); }); trs.each(function(i, tr) { // run something for the tr which second td element's value meets the criteria });

更多推荐

本文发布于:2023-07-06 07:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中为   函数   tr   td   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!