2010-07-28 22 views
15

Jak wybrać wiersze w tabeli html z wyjątkiem wierszy nagłówka tabeli za pomocą jquery?wybierz wiersze w tabeli z wyjątkiem wierszy nagłówka tabeli

<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 cate: http://stackoverflow.com/questions/3339172/jquery-selector-to-filter-out-th-elements To pytanie jest w bardzo wielu przypadkach w różnych odmianach. – spinon

Odpowiedz

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

Należy zawijać wiersze w elemencie <tbody> (niektóre przeglądarki zrobi to zresztą!), A następnie wybierz dzieci tego tbody:

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

można wykluczyć thead użyciu not

$('#mytable tr').not('thead tr') 
Powiązane problemy