<ul id ="sort">
<li id = '2014-02-07'>tralala<li>
<li id = '2013-02-09'>tralala<li>
<li id = '2014-01-04'>tralala<li>
<li id = '2011-09-05'>tralala<li>
</ul>
我希望结果是:
<ul id ="sort">
<li id = '2014-02-07'>tralala<li>
<li id = '2014-01-04'>tralala<li>
<li id = '2013-02-09'>tralala<li>
<li id = '2011-09-05'>tralala<li>
</ul>
我想在jQuery或Javascript中使用id对desc li进行排序。谢谢
答案 0 :(得分:1)
你可以这样做:
var list = $('#sort'),
items = list.children().get();
list.append(items.sort(function(a, b){
return new Date(b.id) - new Date(a.id);
}));