gpt4 book ai didi

javascript - 如何使用路径设置正确的javascript路径

转载 作者:行者123 更新时间:2023-12-03 04:45:26 29 4
gpt4 key购买 nike

我想知道是否有人可以帮助我更正此代码。

我正在尝试使用 var path = window.location.href;为主 URL、俄语网站和西类牙语网站设置 3 个不同的按钮菜单。

我似乎有三分之二在工作。

如果我不能最好地解释这一点,我也很抱歉,但下面是我正在尝试做的事情。希望有人能找出我做错了什么并提供帮助。

        var path = window.location.href;
if (~path.indexOf("/ru/")){
$j("#button1").append("<a class=\"ru-text\" href=\"http://#/\"> <span>Отслеживание </span><br/>отгрузки</a>");
}
var path = window.location.href;
if (~path.indexOf("/es/")){
$j("#button1").append("<a class=\"es-text\" href=\"http://#/\"> <span>RASTREAR </span><br/>ENVIO</a>");
}
}else{
$j("#button1").append("<a href=\"http://#/\"><span>Track Your</span> <br/>shipment here</a>");
};
};

最佳答案

你的if-else条件有误,应该如下:

var path = window.location.href, linkEl = "";

if (~path.indexOf("/ru/")) {
linkEl = "<a class=\"ru-text\" href=\"http://#/\"><span>Отслеживание</span><br/>отгрузки</a>";
} else if (~path.indexOf("/es/")) {
linkEl = "<a class=\"es-text\" href=\"http://#/\"><span>RASTREAR </span><br/>ENVIO</a>";
} else {
linkEl = "<a href=\"http://#/\"><span>Track Your</span><br/>shipment here</a>";
}
$j("#button1").append(linkEl);

关于javascript - 如何使用路径设置正确的javascript路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42890175/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com