我在标题中有一个带有数字ID的链接列表,使用jQuery如何以id顺序从高到低排序
e.g。
<a href="link.html" title="5601">Link</a>
<a href="link.html" title="6001">Link</a>
<a href="link.html" title="7801">Link</a>
<a href="link.html" title="5618">Link</a>
<a href="link.html" title="4101">Link</a>
<a href="link.html" title="2001">Link</a>
到
<a href="link.html" title="7801">Link</a>
<a href="link.html" title="6001">Link</a>
<a href="link.html" title="5618">Link</a>
<a href="link.html" title="5601">Link</a>
<a href="link.html" title="4101">Link</a>
<a href="link.html" title="2001">Link</a>
答案 0 :(得分:4)
这个怎么样:http://james.padolsey.com/javascript/sorting-elements-with-jquery/
使用此功能,您可以沿着$("a").sortElements(function(a, b){
return $(a).attr("title") < $(b).attr("title") ? 1 : -1;
});