设为首页 加入收藏

TOP

map字典,储存cookie,切换账户,展示购物车不同商品(四)
2019-09-17 18:25:36 】 浏览:64
Tags:map 字典 储存 cookie 切换 账户 展示 购物车 不同 商品
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(); }) } });
首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Web前端——JavaScript笔记 下一篇JavaScript banner轮播 左右切换 ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目