我想知道是否有人可以帮我纠正这段代码。
我正在尝试使用var path = window.location.href;
为主要网址,俄罗斯网站和西班牙语网站设置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>");
};
};
答案 0 :(得分:1)
你有错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);