简体   繁体   English

当我们选中和取消选中其他表中的复选框时,如何在jquery中的表中添加/删除行?

[英]How to Add/remove row in table in jquery when we check and uncheck the checkbox in other table?

i have one table where i have select the row by checking check box. 我有一张桌子,我通过选中复选框来选择该行。 I wanted to add selected checkbox rows to another table which is dynamically created when some one check checkbox. 我想将选定的复选框行添加到另一个表中,该表是在某个复选框被选中时动态创建的。

I am waiting for you response 我在等你的回复

Something like 就像是

$("#firsttableid input:checkbox").click(function(){
    $(this).closest("tr").appendTo("#yoursecondtableid");
});

Edit 编辑

If you dont' want to move the row then you can use .clone() to the row and then append to the other table like. 如果您不想移动该行,则可以使用.clone()到该行,然后追加到另一个表中。 Also a change in the click handler to not add the row when the checkbox is unchecked. 另外,单击处理程序中的一项更改是在取消选中复选框时不添加行。 If you don't want to add a row again and again you have to take care of that too. 如果您不想一次又一次地添加一行,则也必须注意这一点。

$("#firsttableid input:checkbox").click(function(){
    if ($ (this).is(":checked"))
    {
        $(this).closest("tr").clone().appendTo("#yoursecondtableid");
    }
});

Working Demo 工作演示

Working Demo with remove 使用删除工作演示

Basically as rahul suggested but a minor addition adding clone() 基本上如rahul所建议的那样,但添加了clone()进行了少量添加

$('#first_table_id input:checkbox').click(function() {
    $(this).closest('tr').clone().appendTo('#second_table_id');
});

Jquery API documentation is your friend :) jQuery API文档是您的朋友:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM