<div id="parent_${id}"></div>
var tableHead = "<table id='ftTableID'><thead><th class='th4'>First Name</th><th class='th5'>Last Name</th><th>Action</th></thead>")}"+"";
$('#parent_itemId').prepend(tableHead);
$('#ftTableID').append("</table>");
在此之後追加新tr
到div
:我們是否可以得到布爾值(true或false)是否刪除的tr是否在div內?
var $newElem = $("<tr>").html(elem).attr({'id': id + num1, 'no': num1});
// creates the "Remove" button
var $removeButton = $('<input type="button" class="deleteButton" value="Delete" /></tr>').appendTo($newElem);
$removeButton.attr({
id: 'remove_' + id,
value: removeBtnLabel ? removeBtnLabel : 'Remove',
disabled: 'disabled'
});
// binds handler to the 'click' JS event of the "Remove" button
$removeButton.click(function() {
removeItem(id, num1, min);
});
追加tr
到div
:
$('#parent_' + id).append($newElem);
首先tr
將在上述div id
被追加與ADD和取消旁邊的按鈕 。雖然我們點擊ADD按鈕,下一步tr
將加入ADD和取消旁邊的按鈕。 ADD按鈕將被省略,從第一個tr
只剩下取消按鈕在第一個tr
等等。現在當我按CANCELL按鈕時,我需要知道刪除的行(tr
)是否是最後一行?
現在,當調用removeItem()函數時,我想查找tr
是否是最後的tr
?
'$( 'TR:去年')'試試這個選擇器':last'或方法'.last()' – guradio
每個'tr'是否都有自己的取消按鈕,它會刪除那個'tr'? – wmash
是的,每個tr都有自己的取消按鈕,可以刪除相應的tr @wmash –