function changeDot(){
var $counts = $strTop.find('.count');
var total = 0;
for(let i = 0 ; i < $counts.length; i++){
total += parseInt($($counts[i]).text());
}
if (total>0){
$('.dot-num').show().text(total);
}else{
$('.dot-num').hide();
}
}
function addClick(){
$('.shop-bar').on('click', '.shop-icon', (e) =>{
//toggle是jquery的方法,作用是改变状态
$('.mask').toggle();
$strTop.toggle();
});
$strTop.on('click', '.plus', (e)=>{
var $count = $(e.currentTarget).parent().find('.count');
$count.text(parseInt($count.text() || '0') + 1);
var $item = $(e.currentTarget).parents().find('.choose-item').first();
var itemData = $item.data('itemData');
itemData.chooseCount += 1;
renderItems();
$('.left-item.active').click();
});
$strTop.on('click', '.minus', (e)=>{
var $count = $(e.currentTarget).parent().find('.count');
if($count.text() == 0) return;
$count.text(parseInt($count.text() || '0') - 1);
var $item = $(e.currentTarget).parents().find('.choose-item').first();
var itemData = $item.data('itemData');
itemData.chooseCount -= 1;
renderItems();
$('.left-item.active').click();
});
}
上面那个方法是计算数量的,注意在parseint后要把$counts变为jquery对象,不然识别不了