我對jQuery和fooTable很新穎。FooTable:將添加和刪除行合併爲一個函數
我想要做的是組合添加和刪除FooTable提供的jQuery功能,這樣當我添加一行時,它會自動刪除該表中的最後一行。
非常感謝這裏的一些幫助。謝謝!
//This piece of code deletes a row
$('table').footable().on('click', '.row-delete', function(e) {
e.preventDefault();
//get the footable object
var footable = $('table').data('footable');
//get the row we are wanting to delete
var row = $(this).parents('tr:first');
//delete the row
footable.removeRow(row);
});
//This piece of code adds a row
$('.add-row').click(function(e) {
e.preventDefault();
//get the footable object
var footable = $('table').data('footable');
//build up the row we are wanting to add
var newRow = 'Some content here'
//add it
footable.appendRow(newRow);
});
您是否需要用新的行替換現有的行(不一定是最後一行)?我找到了解決這個問題的方法,但我認爲它仍然是[Footable]的一個未解決的問題(https://github.com/bradvin/FooTable/issues/241)。 – twigmac