checkBox的全选与全不选

时间:2021-12-01 09:54:04
//初始加载 $(function () {   LoadCart(); }); var RMB = 0; var Index = 0; var shu = 0; var ResultStr = ""; var userID = 0; function LoadCart() { var parameter = { action: "loadcart" }; var ResultStr = ""; $.ajax({ type: "Post", async: true, cache: false, url: "/ashx/ZWY.ashx", data: parameter, dataType: "json", crossDomain: true, success: function (data) { if (data.Success == 1) {   if (data.ObjDataList.Objdata.length > 0) { var price = "";     price += " <tr class=\"quanxun\" style=\"border: 1px solid #eaeaea;\">"; price += " <th width=\"13%\">"; price += " <input class=\"selectAll\" onclick=\"quanxuan()\" checked=\"\" type=\"checkbox\" id=\"chch\" name=\"checkbox22\" value=\"\" />全选</th>"; price += " <th>职业人名称</th>"; price += " <th>职业类型</th>"; price += " <th>订单金额(元)</th>"; price += " <th>订金金额(元)</th>"; price += " <th>操作</th>"; price += " </tr>"; price += " <tr class=\"jg\">"; price += " <td colspan=\"6\">&nbsp;</td>"; price += " </tr>";   price += " <tr id=\"prr\">";     price += " </tr>"; $.each(data.ObjDataList.Objdata, function (i, item) { userID = item.CartID;   RMB += item.SvrRMB; shu = i; Index += i;       price += " <tr class=\"m-judge\" style=\"border-top: 1px solid #eaeaea; border-bottom: 1px solid #eaeaea;\">"; price += ""; price += " <td class=\"checkBtn\">"; price += " <input name=\"checkbox\" class=\"checkbox0\" checked=\"\" onclick='javascript:sum("+i+"," + item.SvrRMB + ");' id=\"checkbox" + i + "\" ushop=\"4a2a19d3-a2f4-40d3-96e4-454a98202f28\" useri=\"97bf6d07-deea-4af8-95a3-983472b63306\" type=\"checkbox\" /><img style=\"cursor: pointer;\" width=\"62\" height=\"62\" onclick=\"jumpNewPage\('4a2a19d3-a2f4-40d3-96e4-454a98202f28','XIAOYU','')\" src=\"" + item.AvatarImage + "\" />"; price += " </td>"; price += " <td>"; price += ""; price += ""; price += " <a href=\"#\" target=\"_blank\">"+item.RealName+"</a>"; price += ""; price += ""; price += "";   price += " </td>"; price += " <td>"; if (item.UserIdentity == 3) { price += "主持人"; } else if (item.UserIdentity == 4) { price += "摄影师"; } else if (item.UserIdentity == 5) { price += "摄像师"; } else if (item.UserIdentity == 6) { price += "化妆师"; }   price += " </td>"; price += " <td><em class=\"totalB\">" + item.SvrRMB + "</em></td>"; price += " <td><em class=\"depositB\">"+item.SvrRMB/2+"</em></td>"; price += " <td><em class=\"depositB1\"><a href=\"#\" >删除</a></em></td>"; price += " </tr>"; ResultStr += " <span class=\"rf\">已选中的婚礼人<em class=\"num\" id=\"totalPeople\">" + (Index + 1) + "</em>个&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += "订单总价:<em>¥</em><em class=\"num\" id=\"totalPrice\">" + RMB + "</em>&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += "您需要支付订金:<em>¥</em><em id=\"depositPrice\" class=\"num\">" + RMB / 2 + "</em>&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += " <a href=\"/upages/Shopping/cartOrder.aspx?UserID=" + item.CartID + "&MoneyID="+RMB+"\" class=\"qjs01 payButton\" id=\"payButton\">去结算</a>"; ResultStr += " </span>";   $("#allMtp").empty(); $("#allMtp").html(ResultStr);   }); $("#prr").empty(); $("#prr").html(price);         } else {   } } else { layer.msg(data.SuccessStr, { icon: 2 }); } } }); } var jk = 0; function sum(i, www) { if ($('input[id="checkbox' + i + '"]').prop("checked")) { Index = Index + 1; RMB = RMB + www; ResultStr = "";   ResultStr += " <span class=\"rf\">已选中的婚礼人<em class=\"num\" id=\"totalPeople\">" + (Index + 1) + "</em>个&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += "订单总价:<em>¥</em><em class=\"num\" id=\"totalPrice\">" + RMB + "</em>&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += "您需要支付订金:<em>¥</em><em id=\"depositPrice\" class=\"num\">" + RMB / 2 + "</em>&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += " <a href=\"/upages/Shopping/cartOrder.aspx?UserID=" + userID + "&MoneyID=" + RMB + "\" class=\"qjs01 payButton\" id=\"payButton\">去结算</a>"; ResultStr += " </span>"; } else { //alert("没选中"); chch.checked = false; Index = Index - 1; RMB = RMB - www; ResultStr = "";   ResultStr += " <span class=\"rf\">已选中的婚礼人<em class=\"num\" id=\"totalPeople\">" + (Index + 1) + "</em>个&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += "订单总价:<em>¥</em><em class=\"num\" id=\"totalPrice\">" + RMB + "</em>&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += "您需要支付订金:<em>¥</em><em id=\"depositPrice\" class=\"num\">" + RMB / 2 + "</em>&nbsp;&nbsp;&nbsp;&nbsp;"; ResultStr += " <a href=\"/upages/Shopping/cartOrder.aspx?UserID=" + userID + "&MoneyID=" + RMB + "\" class=\"qjs01 payButton\" id=\"payButton\">去结算</a>"; ResultStr += " </span>"; }     $("#allMtp").empty(); $("#allMtp").html(ResultStr); }     function quanxuan() { if ($('#chch').prop("checked")) { $('input[name="checkbox"]').each(function (index,item) { if ($(item).prop("checked")) {   } else { $(item).trigger('click'); } });     } else { $(".checkbox0:checked").trigger('click'); }     --------------------------------------------------------------------------------------------------------- var idarray = []; //遍历选中路径 $('input[name="checkbox"]:checked').each(function () { idarray.push($(this).val()); }); for (var i = 0; i < idarray.length; i++) { alert(idarray[i]); }   //全选与全不选 if ($('#chch').prop("checked")) {   $('input[name="checkbox"]').attr("checked", true); //$('input[name="checkbox"]').trigger('click'); } else { $('input[name="checkbox"]').attr("checked", false); }