博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js中的延迟加载
阅读量:7008 次
发布时间:2019-06-28

本文共 1716 字,大约阅读时间需要 5 分钟。

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

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

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

 

点击的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("正在获取优惠卷,请等待!");    }    $.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;//保存用户最初的优惠劵信息

 

转载地址:http://skjtl.baihongyu.com/

你可能感兴趣的文章