使用Jquery将表行从一个表移动到另一个表 [英] Moving table row from one table to the other using Jquery

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

问题描述

我有以下HTML

<table id="tbl1">
  <!-- Table row trHeader should be here based on a flag //-->  
</table>
<table id="tbl2">
  <tr id="trHeader">
     <td>test</td>
  </tr>
</table>

我有一个标志(实际上是一个按钮),我用它来移动表格行id =tbl2。如何根据此标志将其切换回相同位置。

I have a flag (essentially a button), that I use to be able to move the table row with id="tbl2". How would I switch it back to the same position based on this flag.

推荐答案

尝试这样的事情

$('#tbl1').append($('#trHeader').remove());

更新,我不知道你的按钮在哪里切换,我要去假设您单击标题行时切换。如果不是这样,请告诉我。

Update, I'm not sure where your button is to do the toggling, I'm going to assume that your toggling when you click the header row. If otherwise, let me know.

$('#trHeader').toggle(function() {
  $('#tbl1').append($(this).remove());
}, function() {
  $('#tbl2').append($(this).remove());
});

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

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