2

我想做他以下,但它不起作用:

if(pathname == '/ik/services/' || '/ik/recruitment/'){
   //run function
}

它完全忽略了我的 if 语句并执行所有页面的代码......

4

5 回答 5

7

你必须做这样的事情:

if(pathname == '/ik/services/' || pathname == '/ik/recruitment/'){
   //run function
}

|| '/ik/recruitment/'将永远是真实的,因此您的 if 语句中的代码将始终运行。

于 2013-04-09T11:56:46.730 回答
4

尝试

if(pathname == '/ik/services/' || pathname == '/ik/recruitment/'){

或者

jQueryinArray

例子

var arr = ['/ik/services/','/ik/recruitment/'];

if($.inArray(pathname , arr) !== -1)
于 2013-04-09T11:57:19.553 回答
2

这与jQuery无关,它只是一个普通的JS“错误”。您需要将两个字符串与变量进行比较:

if (pathname == 'foo'  || pathname == 'bar') 
于 2013-04-09T11:58:22.747 回答
1

试试这个:

if((pathname == '/ik/services/') || (pathname == '/ik/recruitment/')){
   //run function
}
于 2013-04-09T11:56:56.823 回答
1

尝试做

    if(pathname == '/ik/services/' || pathname == '/ik/recruitment/'){
      //run function
    }
于 2013-04-09T11:57:12.760 回答