Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用path设置正确的javascript路径_Javascript_Url_Text - Fatal编程技术网

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

如何使用path设置正确的javascript路径,javascript,url,text,Javascript,Url,Text,我想知道是否有人能帮我更正这个代码 我正在尝试使用var path=window.location.href设置3个不同的按钮菜单;对于主URL,俄文站点和西班牙文站点 我似乎有三分之二的人在工作 我也很抱歉,如果我不是最好的解释这一点,但下面是我试图做的。希望有人能找出我做错了什么并帮助我 var path = window.location.href; if (~path.indexOf("/ru/")){ $j("#button1")

我想知道是否有人能帮我更正这个代码

我正在尝试使用var path=window.location.href设置3个不同的按钮菜单;对于主URL,俄文站点和西班牙文站点

我似乎有三分之二的人在工作

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

        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>");
    };
};
如果有其他条件,则应如下所示:

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);