2010-07-28 83 views
15

如何选择表格行中使用jQuery的表格行除外?在表格行中选择行除表格标题行

<table id="mytable"> 
     <thead> 
      <tr> 
       <th> 
        Foo 
       </th> 
       <td> 
        Lorem 
       </td> 
       <td> 
        Ipsum 
       </td> 
      </tr> 
     </thead> 
     <tr> 
      <th> 
       Bar 
      </th> 
      <td> 
       Dolor 
      </td> 
      <td> 
       Sit 
      </td> 
     </tr> 
     <tr> 
      <th> 
       Baz 
      </th> 
      <td> 
       Amet 
      </td> 
      <td> 
       Consectetuer 
      </td> 
     </tr> 
    </table> 
+0

Dupli凯特:http://stackoverflow.com/questions/3339172/jquery-selector-to-filter-out-th-elements 这个问题是在无数次在不同的变化。 – spinon 2010-07-28 08:02:13

回答

20
$('tr').not('thead tr').addClass('selected') 
21

你应该换行的<tbody>元素(有些浏览器会做到这一点反正!),然后选择TBODY的孩子:

$('#mytable > tbody > tr'); 
4

您可以排除thead使用not

$('#mytable tr').not('thead tr')