如何移动< tr>在< table>中向上或向下通过jQuery吗? [英] How to move a <tr> up or down within <table> via jQuery?

查看:51
本文介绍了如何移动< tr>在< table>中向上或向下通过jQuery吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行此操作的优雅方法是什么?

What's the elegant way to do this?

推荐答案

这是我为您编写的一个快速插件. 在表上调用它,并为其指定旧行和新行的位置.

Here's a quick plugin I wrote for you. Call it on a table, and give it the the old row and the new row position.

$.fn.extend({ 
  moveRow: function(oldPosition, newPosition) { 
    return this.each(function(){ 
      var row = $(this).find('tr').eq(oldPosition).remove(); 
      $(this).find('tr').eq(newPosition).before(row); 
    }); 
   } 
 }); 

$('#myTable').moveRow(4, 3);

以下是jsbin的示例: http://jsbin.com/uroyi

Here's an example on jsbin: http://jsbin.com/uroyi

这篇关于如何移动< tr>在< table>中向上或向下通过jQuery吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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