如何使用jQuery删除表中的行?
我有一个Bootstrap表如下,
First Name Last Name Age Delete Mickey Mouse 5 Tom Cat 6 Pooh Bear 4 Donaled Duck 7 Jerry Mouse 8 </table
每当用户点击垃圾按钮时,该特定行都将被删除。 我怎样才能使用jQuery实现这一目标?
这是我到目前为止的链接 – http://jsbin.com/gabodamace/edit?html,output
提前致谢!
$('table').on('click','.delete',function(){ $(this).parents('tr').remove(); });
在你的代码中添加class="btn btn-default btn-sm delete
。添加类delete
将帮助你在其他处理程序中使用btn
类.remove()
函数删除该选择器的整个html。
请参阅jsFiddle: https ://jsfiddle.net/jagrati16/o7bu09jr/1/
如下所示:
$('.btn-default').click(function(){ $(this).parents('tr').remove(); })
尝试演示: JsFiddle