例子:在商城详情页中,通过ajax传回来商品的各项参数,根据数组关系找到相应的ID
定义全局样式:
var GoodsID;
var RelationList = [];
var AgentSkuList = {};
var _tempSku = new Array(0);
var globalVar = {};
var AttributeList = {};
$(function () {
GoodsID = GetQueryString("GoodsID");
globalVar.GoodsID = GoodsID;
LoadGoods();
SameBrandGoods();
//商品详情页页面
//固定选择参数框(有2个相同的参数选择框,同步ing~~)
if ($(".rt-side").length) {
var aa = $(".rt-side").offset().top;
$(window).scroll(function () {
var bb = $(window).scrollTop();
if (bb > aa) {
$(".rt-side").css({ "position": "fixed", "top": 0, "left": 1054 + 'px' });
} else {
$(".rt-side").css({ "position": "static" });
}
});
}
//详情页更多选择(当每种参数大于3个时 用模态框的方式来显示)
function initPage() {
var $netContent = $(".netContent");
var more = "<li class='goodsMoreType'><span>" + "更多" + "</span></li>"
$netContent.each(function () {
var list = $(this).find("li");
if (list.length > 3) {
$.each(list, function (i) {
if (i > 2) {
$(this).hide();
}
});
$(this).find(".standard").append(more);
}
});
}
initPage();
/*模态框打开*/
$(".goodsMoreType").on("click", function (e) {
var skuList = AgentSkuList;
$target = $(e.target);
var i = $target.parents(".netContent").index();
var goodsattributeid = $target.parents(".netContent").find(".ltword").data("attributeid");
var valueList = $.grep(AttributeList, function (item) {
if (item.GoodsAttributeID == goodsattributeid) {
return item;
}
});
var Html = "";
$(".goodsMoreTypeModalContent").html("");
valueList = valueList[0].ValueList;
$.each(valueList, function (a, b) {
Html += "<li>" + "<span data-attributevalueid=\"" + valueList[a].GoodsAttributeValueID + "\" class=\"u-btn-choose\">" + valueList[a].AttributeValue + "</span></li>";
});
$(".goodsMoreTypeModalContent").html(Html);
$(".goodsMoreTypeModal").find("#indexOf").val(i);
$(".goodsMoreTypeModal").fadeIn();
});
/*模态框关闭,点击遮罩层关闭*/
$(".close-goodsMoreTypeModal").on("click", function () {
$(".goodsMoreTypeModal").fadeOut();
});
$(".goodsMoreTypeModal").on("click", function (e) {
$target = $(e.target);
var a = $target.parents(".goodsMoreTypeModal-dialog").length;
if (a == "1") {
return true;
} else if (a == "0") {
if ($target.hasClass("goodsMoreTypeModal-dialog")) {
return true;
} else {
$(".goodsMoreTypeModal").fadeOut();
}
}
});
//模态框选择商品
$(".goodsMoreTypeModal-dialog").on("click", "span", function (e) {
$currentTarget = $(e.currentTarget);
if ($currentTarget.hasClass("u-checked")) {
$currentTarget.removeClass("u-checked");
} else {