首先我改名的你Button1
爲您添加行addRowButton
然後我改變委託方法更具體,以addRowButton是從
$('#lastYear').delegate('input[type="button"]'
像這樣:
$('#lastYear')delegate('input[type="button"][id^="addRow"]'
然後委託方法內具體之後
$(this).attr('id', id);
餘之後,下面的一個添加:
var checkid = $(this).attr('id').substring(0,id.length-1);
if (checkid == 'deleteRowButto') // the 'deleteRowButto' is not a mistake
{
$(this).click(function() {
$(this).closest("tr").remove(); // I assign an onclick for the delete button in order to remove a specific row
});
}
編輯:
我做了一些改進,一旦排被刪除前面的添加按鈕顯示,所以我添加下面的代碼:
var showmenow = $(this).closest("tr").prev().find("td:eq(5)").find("input[type='button']");
$(showmenow).show();
$(this).closest("tr").remove();
});
,而不是在原來的代碼刪除按鈕,然後:
$(this).remove();
newIDSuffix++;
我用皮來代替:
$(this).hide();
newIDSuffix++;
見我創建的新jsfiddle。
'ID = 「Button1的」 NAME = 「按鈕2」'!!? – 2013-04-24 00:32:15
介意我問你爲什麼要保留第一行? – MervS 2013-04-24 02:21:52
@ nyde1319應始終至少有一行數據,因此他們需要保持第一行至少。 – user982124 2013-04-26 06:58:31