$(document).ready(function () { getAllPrice(); $("#checkAll").click(function () { if(this.checked == true){ $('[type=checkbox]').prop('checked', true); }else{ $('[type=checkbox]').prop('checked', false); } getAllPrice(); }) $(".son").click(function () { //总的checkbox的个数 var len = $(".son").length; //已选中的checkbox的个数 var checkedLen = $("input[type='checkbox'][name='checked_goods']:checked").length; if(len == checkedLen){ $('#checkAll').prop('checked', true); }else{ $('#checkAll').prop('checked', false); } getAllPrice() }) }); function getAllPrice() { var s = 0.0; $("input[type='checkbox'][name='checked_goods']").each(function () { if(this.checked == true){ var id = "total_price"+$(this).val(); s += parseInt($("#"+id).text()); } }) $("#allPrice").text(s); }
jquery实现购物车复选框总金额的变化以及全选和反选
最新推荐文章于 2023-09-29 16:53:17 发布