$(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實現購物車複選框總金額的變化以及全選和反選
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.