jQuery basic:单击该行的按钮后,如何删除该行? [英] jQuery basic: How can i remove a table row when a button of this row is clicked?

查看:90
本文介绍了jQuery basic:单击该行的按钮后,如何删除该行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$("#tableid tbody:last").append(html);

这将动态创建表行. 每个新创建的行都有一个删除"按钮.

This creates table rows dynamically. Each newly created row has a "remove" button.

现在,如果我单击该删除按钮,该行将被删除. 我该怎么做.

Now if i click that remove button that row will be deleted. How can i do this.

谢谢.

推荐答案

 $(buttonSelector).live ('click', function ()
 {
    $(this).closest ('tr').remove ();
 }
 );

使用.live绑定事件将在动态添加行时自动将其绑定.

using .live to bind your event will bind it automatically when your row is dynamically added.

修改

live已被弃用.

现在要使用的方法是使用on而不是live.

The way to go now is using on instead of live.

$('#tableid').on('click', buttonSelector, function(){
    $(this).closest ('tr').remove ();
});

请参见文档.

这篇关于jQuery basic:单击该行的按钮后,如何删除该行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆