我有一個表格,當用戶在表格的最後一行輸入輸入時,我想附加新行。如何不止一次向表添加新行?
$('table.form-table').on('input', function() {
var tableID = '#' + $(this).closest('table').attr('id');
if(jQuery(this).closest('tr').is(':last-child')) {
var currTR = $(this).closest('tr');
var currTRhtml = '<tr>' + currTR.html() + '</tr>';
var nextRow = jQuery(currTRhtml);
var checkBox = jQuery('<td class="border-right checks"><input type="checkbox" name="del_000" value="000"></td>');
jQuery(tableID).append(nextRow);
checkBox.appendTo(currTR);
}
});
和HTML代碼,如果需要(簡體/修剪):
<table class="form-table" id="XXX" border="1" cellspacing="0" cellpadding="3">
<thead>
<tr class="main"><th nowrap colspan="3" align="left"
class="border-left border-top border-right">
<h3>XXX</h3></th>
</tr>
<tr>
<th>header</th>
</tr>
</thead>
<tbody>
<tr>
<input type="hidden" name="isnew" value="">
<td >
<input type="text"
name="new_text"
value="">
</td>
</tr>
</tbody>
</table>
的問題是,這隻有一次,不會繼續追加新行。這就好像last-child
過濾不會被重置... 有什麼想法?
「input」是一個實際事件嗎? –
@KevinBowersox - 是的,在較新的瀏覽器中,它是 – adeneo
是的.html()丟失... –