如何按三个元素排序

时间:2014-05-02 08:19:36

标签: javascript sorting elements

关于此链接:http://jsfiddle.net/De8Ku/1477/如何开发代码以便我可以按评级进行排序?

    var vA = parseInt($(keySelector, a).text().replace("$",''));
    var vB = parseInt($(keySelector, b).text().replace("$",''));

    return (vA < vB) ? -1 : (vA > vB) ? 1 : 0;

1 个答案:

答案 0 :(得分:0)

添加一些评分,例如......

<a href="#">
    <span class="alpha">D</span>
    <span class="price">$35</span>
    <span class="rating">1.3</span>
</a>

添加链接...

<li>
    <a href="#" id="sRating" class="btnSort">
        Rating
    </a>
</li>

向链接添加数据属性,告诉它按选择器span.rating ...

进行排序
$('#sRating').data("sortKey", "span.rating");

JSFiddle