Js文件-插入窗口.位置到附加的html中

js file - insert window.location into appended html

本文关键字:html 位置 文件 插入 窗口 Js      更新时间:2023-09-26

我有一个附加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&gUrl=ShowMAOAPLogin&lUrl=LLBOAPCouponLPAccessCheck&pgType=MA&storeId=1&catalogId=1&langId=-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"
});