gpt4 book ai didi

javascript - 按日期列对表行 DESC 进行排序,无需插件

转载 作者:行者123 更新时间:2023-11-28 15:31:48 26 4
gpt4 key购买 nike

如何在不使用插件的情况下按日期列对表行 DESC 进行排序?
我搜索过谷歌,但只找到了插件解决方案。

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

最佳答案

这应该适用于 jquery 的降序:

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

关于javascript - 按日期列对表行 DESC 进行排序,无需插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27022535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com