如何从span标签和父标签跟随他(jquery)中遵循排序



我想这样排序:http://jsfiddle.net/chepe263/2SXN9/但只有 span 被排序,<li>标签不跟随<span>标签

$(function(){
var elem = $('‪#‎narrow‬-by-list').find('li.years').sort(sortMe);
function sortMe(a, b) {
return a.className > b.className;
}
$('#narrow-by-list li.month').parent().append(elem);
});
$(function () {
var liContents = [];
$('#narrow-by-list li.month span, #narrow-by-list li.years span').each (function () {
liContents.push(parseInt($(this).text(), 10));
});
liContents.sort(numOrdDesc);
$('#narrow-by-list li.month span, #narrow-by-list li.years span').each (function () {
$(this).text(liContents.pop());
});
});
function numOrdDesc(a, b){ return (b-a); }
<dd>
<ol>
<li rel="0-3 months" class="month">
<a class="amshopby-attr" href="#">0-3 months</a> (3)<span>3</span></li>
<li rel="3-6 months" class="month">
<a class="amshopby-attr" href="#">3-6 months</a> (2)<span>36</span></li>
<li rel="6-9 months" class="month">
<a class="amshopby-attr" href="#">6-9 months</a> (2)<span>69</span></li>
<li rel="9-12 months" class="month">
<a class="amshopby-attr" href="#">9-12 months</a> (1)<span>912</span></li>
<li rel="14-16 years" class="years">
<a class="amshopby-attr" href="#">14-16 years</a> (1)<span>1416</span></li>
<li rel="16+ years" class="years">
<a class="amshopby-attr" href="#">16+ years</a> (1)<span>1600</span></li>
<li rel="2-3 years" class="years">
<a class="amshopby-attr" href="#">2-3 years</a> (5)<span>23</span></li>
<li rel="4-5 years" class="years">
<a class="amshopby-attr" href="#">4-5 years</a> (3)<span>45</span></li>
<li rel="6-7 years" class="years">
<a class="amshopby-attr" href="#">6-7 years</a> (2)<span>67</span></li></ol>
</dd>

我想让李A跟随跨度谢谢。

参见 : http://jsfiddle.net/2SXN9/14/

$(function () {
    var liContents = [];
    $('span').each (function () {
        liContents.push(
            { 
                label : $(this).parent().html(),
                value : parseInt($(this).text(), 10)
            });
    });
    liContents.sort(numOrdDesc);
    $('li').each (function () {
        $(this).html(liContents.pop().label);
    });
});
function numOrdDesc(a, b){ return (b.value-a.value); }

最新更新