abstract:$(function(){ //初始化 doPrice()// 鼠標移上全選框變色效果 $('.fa-check').mouseover(function(){ if($(this).attr('class')!='fa fa-check checked'
$(function(){
//初始化
doPrice()
// 鼠標移上全選框變色效果
$('.fa-check').mouseover(function(){
if($(this).attr('class')!='fa fa-check checked'){
$(this).css('color','#ff6700')
}
})
$('.fa-check').mouseleave(function(){
$(this).css('color','#fff')
})
//普通選擇
$('.fa-check').click(function(){
var cla=$(this).attr('class')
if(cla!='fa fa-check checked'){
$(this).attr('class','fa fa-check checked')
}else{
$(this).attr('class','fa fa-check')
}
doCheckAll()
doPrice()
})
// 全選選擇
$('#check-all').click(function(){
var cla=$(this).attr('class')
if(cla!='fa fa-check checked'){
$('.fa-check').attr('class','fa fa-check checked')
}else{
$('.fa-check').attr('class','fa fa-check')
}
doPrice()
})
// 檢查是否全選
function doCheckAll(){
var allitem=$('.list-item i[class*="fa-check"]').length
var checkeditem=$('.list-item i[class$="checked"]').length
if(allitem!=checkeditem){
$('#check-all').attr('class','fa fa-check')
}else{
$('#check-all').attr('class','fa fa-check checked')
}
}
//加減按鈕
$('.plus').click(function(){
var nowvalue=$(this).siblings('input').val()
var nowvalue=parseInt(nowvalue)
// var currentvalue=0
var currentvalue=nowvalue+1
$(this).siblings('input').val(currentvalue)
var danjia=parseFloat($(this).parents('.good-num').siblings('.good-price').html())
var xiaoji=danjia*currentvalue
//頁面中輸出
$(this).parents('.good-num').siblings('.good-total-price').html(xiaoji+'元')
doPrice()
})
$('.minus').click(function(){
var nowvalue=$(this).siblings('input').val()
var nowvalue=parseInt(nowvalue)
var currentvalue=0
nowvalue<=1?currentvalue=1:currentvalue=nowvalue-1
$(this).siblings('input').val(currentvalue)
var danjia=parseFloat($(this).parents('.good-num').siblings('.good-price').html())
var xiaoji=danjia*currentvalue
//頁面中輸出
$(this).parents('.good-num').siblings('.good-total-price').html(xiaoji+'元')
doPrice()
})
//統(tǒng)計所有勾選的值
function doPrice(){
var items=$('.list-item i[class*="fa-check"]')
var checkeditems=$('.list-item i[class$="checked"]').parents('.select').siblings('.good-total-price')//選中小計的價錢
var totalprice=0//儲存總計
for(var i=0;i<checkeditems.length;i++){
totalprice+=parseFloat(checkeditems[i].innerHTML)
}
$('.sum-price').html(totalprice)
//選中多少件
$('.select-count').html(checkeditems.length)
//總商品數(shù)
$('.all-count').html(items.length)
}
//刪除當前商品
$('.operation').click(function(){
$(this).parents('.list-item').remove()
})
})
Correcting teacher:天蓬老師Correction time:2019-08-15 10:44:31
Teacher's summary:$('.operation').click(function(){
$(this).parents('.list-item').remove()
})
jquery 事件 推薦用on()