2013-12-10 187 views
1

我想遍历我的表行,但我总是有一个错误(无法识别的表达式)。 每个函数被调用时都会出现错误。循环遍历表行

我该如何解决这个问题?

在此先感谢

这里是我的代码:

jQuery的

$("#searchValue").keyup(function() { 

      var table = $(this).siblings('table').not(':hidden'); 
      $(table +" tr").each(function() { 

      }); 
}); 

HTML

<table id='tablePlanning' class='tablesorter'> 
    <thead> 
     <tr> 
      <th>PR Code</th> 
      <th>Klant</th> 
      <th>Description</th> 
      <th>Project status</th> 
      <th>Project Leader</th> 
      <th>Coordinator</th> 
      <th>Account manager</th> 
      <th>Billing</th> 
      <th>Start Datum</th> 
      <th>Hardware</th> 
     </tr> 
    </thead> 
    <tbody> 

    </tbody> 
</table> 

<table id='tableProject' class='tablesorter'> 
    <thead> 
     <tr> 
      <th>Project ID</th> 
      <th>Description</th> 
      <th>Customer</th> 
      <th>Status</th> 
      <th>Max Hours</th> 
      <th>Achieved</th> 
      <th>Difference</th> 
     </tr> 
    </thead> 
    <tbody> 

    </tbody> 
</table> 

回答

4

$(table +" tr")将采取通过table引用的jQuery对象,将其转换为字符串("[object Object]"),将" tr"附加到它,然后尝试使用结果字符串"[object Object] tr"作为选择器。

你可能想find,这是jQuery的对象能够使用的功能,搜索在jQuery对象中的元素中的子元素:

table.find('tr').each(/*...*/); 
0

没有通过可见表循环。

循环遍历可见表格并在每个表格内循环遍历行。

尝试:

$("#searchValue").keyup(function() { 
    $("table:visible").each(function() { 
     $(this).find("tr").each(function(){ 
      //do something 
     }); 
    }); 
}); 
+1

仅有代码的答案很少有很好的答案。解释发生了什么,用户做错了什么,如何改变它等等。 –

0

$( “#searchValue”)KEYUP(函数(){

$('tr:visible','table.tablesorter:visible').each(function(){ 
    var trObj=$(this); 
    //-- your code goes here 
    }); 

});

使用选择器的说明: 选择所有可见表格中的所有可见表格,其类别为“tablesorter”。 & $(this)将引用每个tr对象。