尝试通过href网址对其进行字母顺序修改,而不是使用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>
答案 0 :(得分:0)
改变这个:
var vA = $(keySelector, a).text();
var vB = $(keySelector, b).text();
为:
var vA = $(keySelector, a).attr("href");
var vB = $(keySelector, b).attr("href");
并按网址的最后一部分排序:
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];