zoukankan      html  css  js  c++  java
  • js中的延迟加载

    以京东订单中优惠券获取为例:

    第一次加载时不显示,点击触发时会显示:

    当第一次点击 时会加载优惠券的信息,第二次点击则不再加载,加载后结果为:

    点击的js如下:

    //----------------------------优惠券--------------------------
    function showTicket() {
        if (g('part_ticket').style.display == 'none') {
            g('part_ticket').style.display = '';
            if ($("#couponsArea").html() == null || $("#couponsArea").html() == "") { //通过判断内容是否为null或未空来控制是否加载
                queryCoupons();
            }
        } else {
            g('part_ticket').style.display = 'none';
        }
        setCouponStateShow();
    }
    

     加载js如下:

    function queryCoupons(flag) {
        //第一次查询优惠券列表时,显示"正在获取优惠卷,请等待",以后每次操作优惠券,都都不显示"正在获取优惠卷,请等待"
        if (flag != 1) {
            $("#couponsArea").html("<span class='waitInfo' id='waitInfo'>正在获取优惠卷,请等待!</span>");
        }
        $.getJSON(PurchaseAppConfig.OrderDomain + "/queryCoupons.action?rt=" + Math.random(), function (result) {
            if (result != null) {
                if (result.error != null && result.error != "") {
                    if (result.error == "NoCart") {
                        goCart();
                        return;
                    }
                }
            }
            coupons = result;//保存起来,后面使用或取消优惠劵使用
            var param = processResult(result);
            var data = TrimPath.processDOMTemplate("couponsData", param);
            $("#couponsArea").html(data);
            addLimitInfo();
            $.getJSON(PurchaseAppConfig.OrderDomain + "/checkUseCouponPwd.action?rt=" + Math.random(), function (result) {
                if (result.checkJingDongLpkSafe == false)
                    jingDongLpkNoUse(jingSafeType);
            });
            $.getJSON(PurchaseAppConfig.OrderDomain + "/checkUseDongCouponPwd.action?rt=" + Math.random(), function (result) {
                if (result.checkJingDongLpkSafe == false)
                    jingDongLpkNoUse(dongSafeType);
            });
        });
    }
    var coupons;//保存用户最初的优惠劵信息
    
  • 相关阅读:
    C++ 多线程
    C++ 信号处理
    首页流量监控代码
    macro-name replacement-text 宏 调试开关可以使用一个宏来实现 do { } while(0)
    color depth 色彩深度 像素深度
    数据更新 数据同步 起始点 幂等同步历史数据
    获取当前调用函数名 方法名
    版本号风格为 Major.Minor.Patch
    query_string查询支持全部的Apache Lucene查询语法 低频词划分依据 模糊查询 Disjunction Max
    Cutoff frequency
  • 原文地址:https://www.cnblogs.com/Alight/p/2992873.html
Copyright © 2011-2022 走看看