摘要:$(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();
})
//数量.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 + '元');//为什么&不对
updateTotalPrice()
});
$('.minus').click(function(){
var nownum=parseInt($(this).siblings('input').val());//****获取输入框的值val()
nownum-=1;
nownum=nownum<1?1:nownum;
$(this).siblings('input').val(nownum);//****条件表达式
var siglePrice=nownum*parseFloat($(this).parents('.good-num').siblings('.good-price').html());//获取元素内容html()
$(this).parents('.good-num').siblings('.good-total-price').html(siglePrice + '元')//设置元素内容html()
updateTotalPrice()
})
//siglePrice*=parseFloat($(this).parents('list-item').find('.good-price').html())//为什么获取不到??.eq(0)
//$(this).parents('list-item').find('.good-total-price').html(siglePrice + '元')//为什么获取不到??
//更新总价.sum-price 更新总件数.all-count,选中件数.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
老师总结:没有不熟练这么一说 都是从不会到熟练到理解透彻的 一定要下功夫多去练习!