【问题标题】:js file - insert window.location into appended htmljs 文件 - 将 window.location 插入附加的 html
【发布时间】:2011-09-09 18:48:15
【问题描述】:

我有一个附加 html 的 js 文件。对于一个特定的相对链接,我需要链接是 https。我假设我会设置一个 var,但我不确定如何将它插入到 js 文件中附加的 html 中。

$('#emailUpdates').append('<div class="head-popin ac-popin"><ul><li><a href="/webapp/wcs/stores/servlet/LLBLoginRedirectCmd?feat=ln&gUrl=ShowMAOAPLogin&lUrl=LLBOAPCouponLPAccessCheck&pgType=MA&storeId=1&catalogId=1&langId=-1">Coupon Lookup</a></li></ul></div>').css({
                    "padding-left": "78px"
                });

所以上面的链接,我希望上面的内容类似于https:// +window.location.hostname +/webapp/wcs/stores/servlet/LLBLoginRedirectCmd?feat=ln&amp;gUrl=ShowMAOAPLogin&amp;lUrl=LLBOAPCouponLPAccessCheck&amp;pgType=MA&amp;storeId=1&amp;catalogId=1&amp;langId=-1

但我不确定如何在这个例子中获得这种效果。

谢谢

【问题讨论】:

    标签: javascript variables var window.location


    【解决方案1】:

    这样的?

    var href = 'https://' + window.location.hostname + '/webapp/wcs/stores/servlet/LLBLoginRedirectCmd?feat=ln&gUrl=ShowMAOAPLogin&lUrl=LLBOAPCouponLPAccessCheck&pgType=MA&storeId=1&catalogId=1&langId=-1';
    
    var html = '<div class="head-popin ac-popin"><ul><li><a href="' + href + '">Coupon Lookup</a></li></ul></div>';
    
    $('#emailUpdates').append(html).css({
        "padding-left": "78px"
    });
    

    【讨论】:

    • 谢谢。我无法理解它,也没有想到要使用两个变量
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 2023-03-08
    相关资源
    最近更新 更多