????:$(function(){//全選框$('#check-all').click(function(){if ($(this).hasClass('fa fa-check checked')){$('.fa-check').attr('class','fa fa-check')}else{$('.fa-check
$(function(){
//全選框
$('#check-all').click(function(){
if ($(this).hasClass('fa fa-check checked')){
$('.fa-check').attr('class','fa fa-check')
}
else{
$('.fa-check').attr('class','fa fa-check checked')
}
updateTotalPrice();
})
//單選框.fa-check
$('.fa-check:gt(0)').click(function(){
if ($(this).hasClass('fa fa-check checked')){
$(this).attr('class','fa fa-check')
$('.fa-check:eq(0)').attr('class','fa fa-check')
}else{
$(this).attr('class','fa fa-check checked')
}
if($('.fa-check[class $= checked]').length==($('.fa-check').length-1)) {
$('.fa-check:eq(0)').attr('class','fa fa-check checked')
}
updateTotalPrice();
})
//數(shù)量.num-value
$('.plus').click(function(){
var nownum=parseInt($(this).siblings('input').val());
nownum+=1;
$(this).siblings('input').val(nownum);
var siglePrice=nownum*parseFloat($(this).parents('.good-num').siblings('.good-price').html());
$(this).parents('.good-num').siblings('.good-total-price').html(siglePrice + '元');//為什么&不對(duì)
updateTotalPrice()
});
$('.minus').click(function(){
var nownum=parseInt($(this).siblings('input').val());//****獲取輸入框的值val()
nownum-=1;
nownum=nownum<1?1:nownum;
$(this).siblings('input').val(nownum);//****條件表達(dá)式
var siglePrice=nownum*parseFloat($(this).parents('.good-num').siblings('.good-price').html());//獲取元素內(nèi)容html()
$(this).parents('.good-num').siblings('.good-total-price').html(siglePrice + '元')//設(shè)置元素內(nèi)容html()
updateTotalPrice()
})
//siglePrice*=parseFloat($(this).parents('list-item').find('.good-price').html())//為什么獲取不到??.eq(0)
//$(this).parents('list-item').find('.good-total-price').html(siglePrice + '元')//為什么獲取不到??
//更新總價(jià).sum-price 更新總件數(shù).all-count,選中件數(shù).select-count
function updateTotalPrice(){
var nowTPrice=0;
var ni=$('.list-item i[class$="checked"]').length
for (var ii=0;ii<ni;ii++){
nowTPrice+=parseFloat($('.list-item i[class$="checked"]').eq(ii).parents('.select').siblings('.good-total-price').html());//*** */
}
$('.sum-price').html(nowTPrice+'元')
$('.all-count').html($('.list-item').length)
$('.select-count').html($('.list-item i[class$="checked"]').length)
}
})
//不好寫,不熟練
?? ???:韋小寶?? ??:2019-02-13 10:08:12
???? ??:沒有不熟練這么一說 都是從不會(huì)到熟練到理解透徹的 一定要下功夫多去練習(xí)!