目前有一種tr.header TD,但我需要它是在空THEAD TR日jQuery的追加.header到THEAD TR日
$("#new table tr.Header td").each(function(){
$(this).appendTo("thead tr th");
});
其實,這工作,但我的問題是,多個表存在於DOM中。我不需要所有標題中的每個標題。我只需要將每個表格的tr.header附加到the tr tr th。標題1將被附加到表格1的thead ...等等。
我該如何做到這一點?
目前的結果是:
<table>
<thead>
<tr>
<th>Header 1 Header 2 Header 3 Header 4</th>
</tr>
</thead>
<tbody><tr><td>
Row 1
</td></tr>
<tr><td>
Row 2
</td></tr>
<tr><td>
Row 3
</td></tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Header 1 Header 2 Header 3 Header 4</th>
</tr>
</thead>
<tbody><tr><td>
Row 1
</td></tr>
<tr><td>
Row 2
</td></tr>
<tr><td>
Row 3
</td></tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Header 1 Header 2 Header 3 Header 4</th>
</tr>
</thead>
<tbody><tr><td>
Row 1
</td></tr>
<tr><td>
Row 2
</td></tr>
<tr><td>
Row 3
</td></tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Header 1 Header 2 Header 3 Header 4</th>
</tr>
</thead>
<tbody><tr><td>
Row 1
</td></tr>
<tr><td>
Row 2
</td></tr>
<tr><td>
Row 3
</td></tr>
</tbody>
</table>
沒有任何jQuery的表都出現這樣的:
<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody><tr class="Header"><td>
Header 1
</td></tr>
<tr><td>
Row 1
</td></tr>
<tr><td>
Row 2
</td></tr>
<tr><td>
Row 3
</td></tr>
</tbody>
</table>
完全不清楚你想要什麼。你想讓它看起來像你展示的?如果是這樣,在改變之前它是什麼樣子? – Hogan 2013-03-06 20:15:54
@Hogan,我相信他想要的東西就像我的回答(帶我三次閱讀...) – gdoron 2013-03-06 20:17:23
對不起,不清楚。我修改了問題。 – arkjoseph 2013-03-06 20:22:31