PC端商城详情页脚本

该博客探讨了如何在PC端商城详情页面中利用Ajax技术动态获取商品信息。通过Ajax请求,从服务器获取商品参数,根据预设的数组关系匹配并显示相应ID的内容。
摘要由CSDN通过智能技术生成

例子:在商城详情页中,通过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 {
          
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值