在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 });
更多推荐
发布评论