按日期列对表行DESC排序,不带插件 [英] Sort table rows DESC by date column, without plugins

查看:82
本文介绍了按日期列对表行DESC排序,不带插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有插件的情况下按日期列对表行DESC进行排序?
我已经搜索过google,但只找到了插件解决方案.

HTML示例:

How can I sort table rows DESC by date column, without plugins?
I've searched google, but only found plugin solutions.

HTML Example:

<html>
<body>
    <table>
        <thead>
            <th>Date</th>
        </thead>
        <tbody>
        <tr>
            <td><input value="01/01/2010"></td>
        </tr>
        <tr>
            <td><input value="01/01/2012"></td>
        </tr>
        <tr>
            <td><input value="01/01/2011"></td>
        </tr>
        <tr>
            <td><input value="01/01/2013"></td>
        </tr>
        </tbody>
    </table>
</body>
</html>

JSFiddle:
http://jsfiddle.net/6o4tfxo0/

推荐答案

这对于使用jquery降级应该起作用:

This should work for descending with jquery:

$('tr').sort(function(a,b){
    return new Date($(a).find('input').val()).getTime() < new Date($(b).find('input').val()).getTime() 
}).appendTo('tbody')

这篇关于按日期列对表行DESC排序,不带插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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