jq 对结果集进行排序(按价格排序) tab切换



  • 最新

  • 销量

  • 更新

  • 价格






  • 12元





  • 22元





  • 33元



$(function() {
var sortByInput = function(sortBy) {
var sortEle = $('.index_goods>ul').sort(sortBy);
$('.index_goods').empty().append(sortEle);
}
//按价格排序
//parseInt($(a).find('.price_pro').text().replace(/[^0-9]/ig,'')) 获取结果值
var asc = function(a, b) {
return parseInt($(a).find('.price_pro').text().replace(/[^0-9]/ig,'')) > parseInt($(b).find('.price_pro').text().replace(/[^0-9]/ig,'')) ? -1 : 1;
}

var desc = function(a, b) {
    return parseInt($(a).find('.price_pro').text().replace(/[^0-9]/ig,'')) > parseInt($(b).find('.price_pro').text().replace(/[^0-9]/ig,'')) ? 1 : -1;
}
$('.price').on('click',function(){
    var _type= $(this).attr('date-type');
    if (_type =='desc') {
        sortByInput(desc);
        $(this).attr('date-type','asc');
        $('.arrow_up').addClass('active_up');
        $('.arrow_down ').removeClass('active_down');
    }else{
        sortByInput(asc);
        $(this).attr('date-type','desc');
        $('.arrow_up').removeClass('active_up');
        $('.arrow_down ').addClass('active_down');
    }
})

// tab切换  class on 下标
$('.filtrate_term li').on('click',function(){
$(this).attr('class','on').siblings('li').attr('class','');
})

})

你可能感兴趣的:(jq 对结果集进行排序(按价格排序) tab切换)