反转表格行 [英] Invert table rows

查看:20
本文介绍了反转表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 jQuery 反转表 tbody 行.

我有什么:

<头><tr><td>标题A</td><td>TITLE B</td>

(...) 在 jsfiddle 中继续.

这里是我拥有的和我想要的:http://jsfiddle.net/ZaUrP/1/

解决方案

fiddle

与其他人几乎相同,只有我使用 .detach() 来保证保持附加到 tr 的任何疯狂事件完整无缺.我还使用 $.makeArray 来避免反转基本 jQuery 对象上的任何 proto 内容.

$(function(){$("tbody").each(function(elem,index){var arr = $.makeArray($("tr",this).detach());arr.reverse();$(this).append(arr);});});

I want to invert table tbody rows with jQuery.

WHAT I HAVE:

<table width="630" border="0" cellspacing="0" cellpadding="0">
<thead>
 <tr>
    <td>TITLE A</td>
    <td>TITLE B</td>

(...) continue in jsfiddle.

Here what I have and what I want: http://jsfiddle.net/ZaUrP/1/

解决方案

fiddle

pretty much the same as the other guy, only I use .detach() which is guarunteed to keep any crazy events that were attached to the trs intact. I also use $.makeArray to avoid reversing any of the proto stuff on the base jQuery object.

$(function(){
    $("tbody").each(function(elem,index){
      var arr = $.makeArray($("tr",this).detach());
      arr.reverse();
        $(this).append(arr);
    });
});

这篇关于反转表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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