$(function () { $("#xq_size tbody[color=" + $("#xq_color li:eq(0)").attr("id") + "]").show(); $("#xq_color li").on("click", function () { $(this).addClass("selected").siblings().removeClass("selected"); $("#xq_size tbody[color=" + $(this).attr("id") + "]").fadeIn().siblings("tbody").hide(); }) $(".amount-down").on("click", function () { var num = parseInt($(this).next().val()); if (num != 0) { $(this).next().val(num - 1); if (num == 1) { $(this).addClass("amount-down-limit"); } } if ($(this).next().val() < $(this).parents("tr").find(".xq_size_count").attr("count")) { $(this).next().next().removeClass("amount-up-limit"); } total(); }) $(".amount-up").on("click", function () { var num = parseInt($(this).prev().val()); if (num == 0) { $(this).prev().prev().removeClass("amount-down-limit"); } if (num == $(this).parents("tr").find(".xq_size_count").attr("count") - 1) { $(this).addClass("amount-up-limit"); } if (num != $(this).parents("tr").find(".xq_size_count").attr("count")) { $(this).prev().val(num + 1); } total(); }) $(".amount-input").on("keyup", function () { this.value = this.value.replace(/\D/g, '') }) $(".amount-input").on("blur", function () { if ($(this).val() > 0) { $(this).prev().removeClass("amount-down-limit"); } if ($(this).val() == "") { $(this).val(0); } else if (parseInt($(this).val()) >= $(this).parents("tr").find(".xq_size_count").attr("count")) { $(this).val($(this).parents("tr").find(".xq_size_count").attr("count")); $(this).next().addClass("amount-up-limit"); } total(); }) }) //去除字符串前后空格 function trimSpace(str) { return str.replace(/(^\s+)|(\s+$)/g, ""); } //去除字符串中所有空格 function removeAllSpace(str) { return str.replace(/\s+/g, ""); } function total(p) { var txt = $(".amount-input"); var money = 0; var count = 0; var list = ""; var isHaveColorFlag=$('#hfIsHaveColor').val(); if (status == 1) { for (var i = 0; i < txt.length; i++) { count += parseInt(txt.eq(i).val()); if (txt.eq(i).val() != 0 && isHaveColorFlag=="1") { //数量,尺码,尺码名字,颜色,颜色名字 if (list == "") { list += '{"Count":' + trimSpace(txt.eq(i).val()) + ',"SizeId":' + trimSpace(txt.eq(i).parents("tr").find(".xq_size_name").attr("size").replace("size", "")) + ',"SizeName":"' + trimSpace(txt.eq(i).parents("tr").eq(i).find(".xq_size_name").text()) + '","ColorId":' + trimSpace(txt.eq(i).parents("tbody").attr("color").replace("color", "")) + ',"ColorName":"' + trimSpace($("#" + txt.eq(i).parents("tbody").attr("color") + " a").attr("title")) + '"}'; alert('1'); } else { alert('2'); list += ',{"Count":' + trimSpace(txt.eq(i).val()) + ',"SizeId":' + trimSpace(txt.eq(i).parents("tr").find(".xq_size_name").attr("size").replace("size", "")) + ',"SizeName":"' + trimSpace(txt.eq(i).parents("tr").eq(i).find(".xq_size_name").text()) + '","ColorId":' + trimSpace(txt.eq(i).parents("tbody").attr("color").replace("color", "")) + ',"ColorName":"' + trimSpace($("#" + txt.eq(i).parents("tbody").attr("color") + " a").attr("title")) + '"}'; } } } console.log(list); if (price3 > 0 && count >= count3) { money = count * price3; } else if (price2 > 0 && count >= count2) { money = count * price2; } else { money = count * price1; } $("#xq_price span").text(money); $("#xq_count span").text(count); } else { count = $(".amount-input").val(); } if (p == 1) { if (parseInt(count) < parseInt(count1)) { alert("最低起批量为" + count1); return; } else { //先判断登陆情况 if ($('#currentToken').val() != "") { var userid = parseInt($('#hfCurrentUserId').val()); var currentLocation = window.location.href; var currentToken = $('#currentToken').val(); var productId = $('#hProductId').val(); var sourceId = "164202"; var ss = 0; if (status == 1) { list = '{"ProductId":' + productId + ',"UserId":' + userid + ',"CountList":[' + list + ']}'; $.ajax({ type: "GET", url: "http://www.acshoes.com.cn/product/SetShoppingCartSkuByJosonp", // 这个就是不同于当前域的一个URL地址,这里单纯演示,所以同域 //url: posturl, dataType: "jsonp", data: "sku=" + list+"&jsonpcallback=?", // jsonpcallback与上面的jsonp值一致 anysc: true, success: function (data) { alert(data.success); window.location.href = "http://order.acshoes.com.cn/PiFa/OrderDetails?postId=" rel="nofollow" + productId + "&userToken=" + currentToken + "&buyCount=" + count + "&sourceId=" + sourceId + "&backUrl=" + currentLocation + ""; }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("错误"); } }); } else { window.location.href = "http://order.acshoes.com.cn/PiFa/OrderDetails?postId=" rel="nofollow" + productId + "&userToken=" + currentToken + "&buyCount=" + count + "&sourceId=" + sourceId + "&backUrl=" + currentLocation + ""; } } else { if (confirm("您目前尚未登陆账户,是否现在登录?")) { $("#login-modal").modal("show"); } return; } } } }