简体   繁体   English

按日期列对表行DESC排序,不带插件

[英]Sort table rows DESC by date column, without plugins

How can I sort table rows DESC by date column, without plugins? 没有插件,如何按日期列对表行DESC进行排序?
I've searched google, but only found plugin solutions. 我搜索过google,但只找到了插件解决方案。

HTML Example: HTML示例:

<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: 的jsfiddle:
http://jsfiddle.net/6o4tfxo0/ http://jsfiddle.net/6o4tfxo0/

This should work for descending with jquery: 这应该适用于使用jquery降序:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM