0

试图将其调整为按href url而不是href文本按字母顺序排列...

Javascript

function sortUsingNestedText(parent, childSelector, keySelector) {
var items = parent.children(childSelector).sort(function (a, b) {
    var vA = $(keySelector, a).text();
    var vB = $(keySelector, b).text();
    return (vA < vB) ? -1 : (vA > vB) ? 1 : 0;
});
parent.append(items);
}

$(function () { sortUsingNestedText($('.searchresults'), "div", ".title a"); });

HTML

<div class="title"><a href="../url/thisiswhatiwantsorted/default.html">Link</a></div>
4

1 回答 1

0

改变这个:

var vA = $(keySelector, a).text();
var vB = $(keySelector, b).text();

至:

var vA = $(keySelector, a).attr("href");
var vB = $(keySelector, b).attr("href");

并按 url 的最后一部分排序:

var vAURL = $(keySelector, a).attr("href").split('/');
var vA = vAURL[vAURL.length-1];
var vBURL = $(keySelector, b).attr("href").split('/');
var vB = vBURL[vBURL.length-1];
于 2013-02-02T17:24:07.170 回答