0

我对 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);
});
4

2 回答 2

0

这个笨蛋应该按照你的要求做:http: //plnkr.co/edit/PYELgBc0xOpvH4lePXKu

于 2014-01-02T17:08:47.577 回答
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>

http://fiddle.jshell.net/wqk87/

于 2014-01-02T17:19:01.317 回答