[英]Append rows between rows in a table
我有一個以下結構的表,我想動態地將一些行附加到表中。
<table>
<thead>
<tr>
<td>Work</td>
<td>Award</td>
</tr>
</thead>
<tbody>
<tr>
<td><input class="w_name" type='text'/></td>
<td><input class="other" type='text'/></td>
</tr>
<tr>
<td><input class="w_name" readonly/></td>
<td><input class="other" type='text'/></td>
</tr>
<tr>
<td><input class="w_name" type='text'/></td>
<td><input class="other" type='text'/></td>
</tr>
</tbody>
</table>
我有這個 jquery 做附加
$('.btn-add').click(function() {
var index = $('tr', $(this).closest("tbody")).index(this);
alert(index);
var tbody = $('tbody');
var i = $('tbody tr').size() + 1;
tablerow="<tr><td><input class=\"w_name\" type='text'/></td> <td><input class=\"other\" type='text'/></td><td><input class=\"other\" type='text'/></td> <td><input class=\"other\"type='text'/></td><td><input class=\"other\" type='text'/></td><td><input class=\"other\" type='text'/><a href=\"#\" id=\"remScnt\">Remove</a></td><tr>";
tbody.append(tablerow);
i++;
return false;
});
我想在 tbody 的第一個 tr 和最后兩個 trs 之間追加行。 建議!
這是一種方法 -
var newRow = "<tr><td><input class=\"w_name\" type='text'/></td> <td><input class=\"other\" type='text'/></td><td><input class=\"other\" type='text'/></td> <td><input class=\"other\"type='text'/></td><td><input class=\"other\" type='text'/></td><td><input class=\"other\" type='text'/><a href=\"#\" id=\"remScnt\">Remove</a></td><tr>";
$('.add').click(function() {
$(newRow).insertAfter($('tbody tr:first-child'));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.