1选择 select 获取val text 更改其他class值
购物车
地、单选 全选价格计算
// JavaScript Documentvar checkedList = {};function calculate(){ var total = 0; $.each(checkedList,function(id,data){ console.log(id,data); total += checkedList[id].price * checkedList[id].count; }); $("#taotal").html("¥" + total);}/*单选*/$(document).on("change",".onecheck",function(e){ e.preventDefault(); var $li = $(this).parents("li"); var id = $li.attr("data-id"); if($(this).prop('checked')){ var count = $li.find(".num").val(); checkedList[id] = {price:$li.attr("data-price"),count:count}; $(this).next().addClass("active"); }else{ delete checkedList[id]; $(this).next().removeClass("active"); } var allChecked = true; $('.onecheck').each(function(){ if(!this.checked){ allChecked = false; return false; } console.log("xx"); }); console.log('allchecked',allChecked); $('.check-all').prop("checked",allChecked); calculate();});/*所有选项*/$(document).on("change",".check-all",function(e){ e.preventDefault(); console.log( $(".squaredFour input")); $(".onecheck").prop('checked',$(this).prop("checked")).trigger('change'); if($(this).prop('checked')){ $(this).next().addClass('active'); }else{ $(this).next().removeClass('active'); } console.log('all');});/*减商品*/$(document).on("click",".down",function(e){ e.preventDefault(); var $li = $(this).parents("li"); var $input = $li.find(".num"); var origin = parseInt($input.val()); $input.val(origin-1); $input.trigger('input');});/*加商品*/$(document).on("click",".up",function(e){ e.preventDefault(); var $li = $(this).parents("li"); var $input = $li.find(".num"); var origin = parseInt($input.val()); $input.val(origin + 1); $input.trigger('input');});/*改变文本输入*/$(document).on("input",".num",function(e){ e.preventDefault(); var $li = $(this).parents("li"); var id = $li.attr("data-id"); if( checkedList[id] != undefined){ var count = $(this).val(); checkedList[id] = {price:$li.attr("data-price"),count:count}; calculate(); }});{$good->_id}}')">-
全选
合计:¥0.00
不含运费