2014-05-13 47 views
0

我有我的HTML結構是這樣的:jQuery - 我如何選擇這些'th'元素?

<tbody id="tbodyCreateExpense"> 
    <tr> 
     <th>Date(dd/mm/yy)</th> 
     <th>Money(VND)</th> 
     <th>Invoice ID</th> 
     <th>Images</th> 
     <th>Note</th> 
     <th>Actions</th> 
    </tr> 

    <tr class="dataTR"> 
     <th class="es-cr-edit" data-attribute="date"> 
      <div><input class="datepicker" type="text" placeholder="11/11/2013"></div> 
     </th> 
     <th class="es-cr-edit" data-attribute="money"> 
      <div><input type="text"></div> 
     </th> 
     <th class="es-cr-edit" data-attribute="invoiceID"> 
      <div><input type="text"></div> 
     </th> 
     <th> 
      <div class="btn-end" data-attribute="invoiceImage"> 
       <a href="#">Browse </a> 
      </div> 
     </th> 
     <th class="es-cr-edit" data-attribute="note"> 
      <div><input type="text"></div> 
     </th> 
     <th> 
      <figure class="iconsp-remove-25px"></figure> 
      <figure class="iconsp-edit-25px"></figure> 
     </th> 
    </tr> 

    <tr> 
     <th class="es-cr-edit"> 
      <div><input class="datepicker" type="text" placeholder="11/11/2013"></div> 
     </th> 
     <th class="es-cr-edit"> 
      <div><input type="text"></div> 
     </th> 
     <th class="es-cr-edit"> 
      <div><input type="text"</div> 
     </th> 
     <th> 
      <div class="btn-end"> 
       <a href="#">Browse </a> 
      </div> 
     </th> 
     <th class="es-cr-edit"> 
      <div><input type="text"></div> 
     </th> 
     <th> 
      <figure class="iconsp-remove-25px"></figure> 
      <figure class="iconsp-edit-25px"></figure> 
     </th> 
    </tr> 

</tbody> 

現在我要選擇的每(tbody > tr (with class="dataTR) > th)元素,我怎麼能做到這一點使用jQuery? 我試過這種方式:$('#tbodyCreateExpense .dataTR').find("th")$('#tbodyCreateExpense .dataTR')[0].find("th")(這種方式似乎只有當我只有1下面),但他們都沒有工作。

希望你們能幫忙,多謝先進!

+2

'$( '#tbodyCreateExpense .dataTR')找到( 「TH」。 )'是現貨。它將返回一組匹配的jQuery對象。 – Archer

+0

難道你不想在某個時候使用TD? –

+0

您應該使用'TD'元素,而不是'TH'來顯示錶格數據,而不是標題。即使它有效,你也應該使用準確的標記 –

回答

0

您可以使用:

$('tbody tr.dataTR th'); 

Demo

用於遍歷匹配的元素:

$('tbody tr.dataTR th').each(function(){ 
    //code here 
});