我对jquery和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);
});
答案 0 :(得分:0)
这个插件应该按照你的要求进行:http://plnkr.co/edit/PYELgBc0xOpvH4lePXKu
答案 1 :(得分:0)
我建议替换为:
http://api.jquery.com/replacewith/
所以假设你的表就像
<table id="foo">
<tr>
<td>hello</td>
</tr>
</table>
<script>
$("#add-row").on('click',function(){// add-row is your event button
$("#foo tr:last-child").replaceWith( "<tr><td>my new content</td></tr>" );
})
</script>