我很努力設置jquery插入新錶行,然後刪除它們,如果我不需要它們。Jquery添加行,然後刪除它們,如果不需要
例如:
我有一個每個錶行兩個按鈕,就像這樣:
--------------------------------------
|Add/Remove | Name | Id | Color |
--------------------------------------
|Add/Remove | Shirt | 1 | Blue |
--------------------------------------
|Add/Remove | Shirt | 2 | Red |
--------------------------------------
當我點擊「添加」按鈕,它會使用AJAX來走出去,搶數據和在當前行之後插入行。這裏是我的代碼(這工作正常):
$(function() {
$('#example').on('click', 'input[name="cmdAddRow"]', function() {
var curRow = $(this).closest('tr');
$.ajax({
cache: false,
type: 'POST',
url: '{{ path('inventory_low_test_asin_data') }}',
data: '',
success: function(data)
{
var newRow = data.htmlData;
curRow.after(newRow);
}
});
});
});
--------------------------------------
|Add/Remove | Name | Id | Color |
--------------------------------------
|Add/Remove | Shirt | 1 | Blue |
--------------------------------------
| Inserted | A | 1 | Blue | - Need to be able to remove this row
--------------------------------------
| Inserted | B | 1 | Blue | - Need to be able to remove this row
--------------------------------------
| Inserted | C | 1 | Blue | - Need to be able to remove this row
--------------------------------------
| Inserted | D | 1 | Blue | - Need to be able to remove this row
--------------------------------------
|Add/Remove | Shirt | 2 | Red |
--------------------------------------
現在,這是棘手的部分,如果我不需要它插入數據的那些行(有時它會返回向上的,其在當前之後插入20行行),我需要能夠刪除所有一次插入的所有行(不是每次一個)。當我點擊該行的「刪除」按鈕時,這是如何處理的?我不確定爲jQuery寫什麼。
非常感謝您的幫助!
我有,我試過這個,它沒有按需要工作:'('click','input [name =「cmdRemRow」]',function(){(this).closest('tr' )。去掉(); }); – LargeTuna 2013-05-02 18:27:23
你可以發佈這些添加行的HTML標記嗎? – tymeJV 2013-05-02 18:28:09
「它沒有按需要工作」發生了什麼事?有錯誤嗎? – 2013-05-02 18:28:17