4
我有一個表,我試圖在表格單元格的值存在的基礎上創建類似這樣的東西。要獲得如何使用jquery更新表頭
結果 - jsFiddle Result
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="top-table-bg" id="mytable">
<tbody><tr>
<th style="width:200px"><br>First Row<br>Second Row<br>Third Row<br>Forth Row<br></th>
<th style="width:200px"><p>Heading1<br>
</p>
<p>First Row<br>
</p></th>
<th style="width:200px"><p>Heading2
<br>
</p>
<p>Second Row
<br>
Forth Row<br>
</p></th>
<th style="width:200px"><p>Heading3
<br>
</p>
<p>Second Row<br>
Third Row<br>
<br>
</p></th>
</tr>
<tr>
<td style="width:200px;text-align:center;">First Row</td>
<td style="width:200px;text-align:center;">20</td>
<td style="width:200px;text-align:center;"></td>
<td style="width:200px;text-align:center;"></td>
</tr>
<tr>
<td style="width:200px;text-align:center;">Second Row</td>
<td style="width:200px;text-align:center;"></td>
<td style="width:200px;text-align:center;">20</td>
<td style="width:200px;text-align:center;">20</td>
</tr>
<tr>
<td style="width:200px;text-align:center;">Third Row</td>
<td style="width:200px;text-align:center;"></td>
<td style="width:200px;text-align:center;"></td>
<td style="width:200px;text-align:center;">20</td>
</tr>
<tr>
<td style="width:200px;text-align:center;">Forth Row</td>
<td style="width:200px;text-align:center;"></td>
<td style="width:200px;text-align:center;">20</td>
<td style="width:200px;text-align:center;"></td>
</tr>
</tbody></table>
而這就是我試過了,但它的所有值:(
我嘗試填充 - jsFiddle Try
$('#mytable>tbody>tr').each(function(){
if($(this).text() != '') {
$('th').append($(this).children('td').first().text() + "<br>");
}
});
讓我知道我在做什麼錯了..在jquery中啓動..因此,如果基本一個
ok..let我嘗試和檢查 – Trialcoder 2013-02-18 11:01:05
excellent..working就像一個魅力! – Trialcoder 2013-02-18 11:02:24
很高興幫助... – Bruno 2013-02-18 11:02:59