ateElement('div');
div_num.className = 'num';
div1.append(div_num);
let div_minus = document.createElement('div');
let div_plus = document.createElement('div');
let span2 = document.createElement('span');
div_minus.innerHTML = '-';
div_plus.innerHTML = '+';
span2.innerHTML = '0';
div_minus.className = 'minus';
div_plus.className = 'plus';
div_num.append(div_minus);
div_num.append(span2);
div_num.append(div_plus);
}
}
}
$(".plus").click(function() {
var num = $(this).parent().children("span");
//单品数量增加
num.text(parseInt(num.text()) + 1);
//商品总数增加
var totalNum = parseInt($(".totalNum").text());
totalNum++
$(".totalNum").text(totalNum);
//计算总价
var goods_price = parseFloat($(this).parent().parent().children(".goods_price").text());
$(".totalPrice").text(parseFloat($(".totalPrice").text()) + goods_price);
});
//点击减少按钮触发事件
$(".minus").click(function() {
var num = $(this).parent().children("span");
if (parseInt(num.text())) {
num.text(parseInt(num.text()) - 1);
var totalNum = parseInt($(".totalNum").text());
totalNum--
$(".totalNum").text(totalNum);
var goods_price = parseFloat($(this).parent().parent().children(".goods_price").text());
$(".totalPrice").text(parseFloat($(".totalPrice").text()) - goods_price);
} else {
num.text("0");
}
// console.log(parseInt(num.text()));
});
//点击付款
$('#pay_money').click(() => {
console.log($('.totalPrice').text());
if ($('.totalPrice').text() === '00') {
alert('请输入商品数量');
} else {
$('.pay_photo').show(1000);
}
})
$('#pay_close').click(() => {
$('.pay_photo').hide();
})
}
});
|