js 规格多选,选中显示和还可以选择的数量 多维度选择

阅读更多










var list = new Array();
ogoodsSizeListTow.hammer().on('tap',function(e) {
//console.log(e);
var i;
myPub.OffMuiEvent(false);
var _tarTag = e.gesture.target;
    var target;
if(_tarTag.nodeName.toLowerCase() == 'li') {
target = $(_tarTag);
var  flowers = ogoodsSizeListTow.hasClass("Flowers");
if(flowers === true){
if(target.hasClass('active')){
target.removeClass('active');
i = list.length-1
oAddCarONBtn.text('还可以选择'+i+'件');
oAddCarONBtn.css('display','block')
oAddCarOKBtn.css('display','none');
$.each(list,function(i){
if(!list[i].hasClass('active')){
list.arrayRemove(i);
}
});
}
list.push(target);
target.addClass('active');
if(list.length > 3){
list.shift().removeClass('active');
}
i = 3 - list.length;
console.log(i)
oAddCarONBtn.text('还可以选择'+i+'件');
if(i == 0){
oAddCarONBtn.css('display','none')
oAddCarOKBtn.css('display','block');
}
return;
}
}
});

Array.prototype.arrayRemove = function(dx){
if(isNaN(dx)||dx>this.length){return false;}
this.splice(dx,1);
}



  //多维度选择
    oGoodsList.hammer().on('tap',function(e) {
    //console.log(e)
    myPub.OffMuiEvent(false);
    var _tarTag = e.gesture.target;//获取点击的li
    var target;
    if(_tarTag.nodeName.toLowerCase() == 'li') {
    target = $(_tarTag);
    if(target.attr('mobilepar')==0){
console.log(target.attr('mobilepar'));
return false;
}
    target.parents('.goodsSizeList').find('li').removeClass('active');//获取当前点击li的父级下面的所有li并删除class上的active
    target.addClass('active');//添加active
    oUser_seleted.find('span').text(target.text())
      var map = {};//new map
var spanId = target.parents('.js_goodsSizemob').attr('id');//获取当前点击的li的父级ID
map[spanId] = target.text();//用父级id为KEY(键)获取选中的内容;
var s = $.map(map, function(n){//便利map
return n;
}).join(",");//拼接字符串
oUser_seleted.find('span').text(s);
    }
    myPub.HamstopPropaga()
    });

你可能感兴趣的:(多选,array方法扩展)