Multiple comparisons in an if statement using the logical OR operator

前端 未结 5 1885
长发绾君心
长发绾君心 2020-12-11 10:33

I want to do he following, but it does not work:

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

It is compl

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 11:19

    Try

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

    OR

    jQuery inArray

    Example

    var arr = ['/ik/services/','/ik/recruitment/'];
    
    if($.inArray(pathname , arr) !== -1)
    

提交回复
热议问题