使用jQuery将表行从一个表复制到另一个表 [英] Copy a table row from one table to another using jQuery

查看:90
本文介绍了使用jQuery将表行从一个表复制到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够当该行中一个复选框被选中,从一个表复制的一行到另一使用jQuery.

I need to be able to copy a row from one table to the other using jQuery when a checkbox in that row is checked.

我尝试使用.clone()方法,但是这种行为非常奇怪.即使jQuery专门针对第二个表中的行,但是当复制到第一个表中时,它仍然可以被定位.因此,要么clone()不正确,要么我需要使用其他东西.

I tried using the .clone() method but this had very strange behaviour. Even though the jQuery was specifically targeting rows in the second table, when copied to the first, it could still be targeted. So either clone() is not right or I need to use something else.

$('#offers tbody tr td input.checkbox:not(:checked)').click(function (e) {
    var row = $(this).closest('tr');
});

推荐答案

$('#offers tbody tr td input.checkbox:not(:checked)').on('change', function (e) {
     var row = $(this).closest('tr').html();
     $('#otherTable tbody').append('<tr>'+row+'</tr>');
});

查看实际情况! http://jsfiddle.net/3BZp4/1/

克隆也应该为您工作,并且不会影响以后的选择:

Clone also SHOULD work for you and not effect future selection:

http://jsfiddle.net/AkVTw/1/

现在可以根据注释取消捕获:

Now with catch for unchecking as per comments:

http://jsfiddle.net/wGGDb/

这篇关于使用jQuery将表行从一个表复制到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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