I have an if statement to generate active classes, it works in most cases but I have an admin section where you can access the front-end products but the URL changes to use query strings to get the correct page.
我有一个if语句来生成活动类,它适用于大多数情况但我有一个管理部分,您可以访问前端产品,但URL更改为使用查询字符串来获取正确的页面。
For this reason, I am trying to create an if statement to say, if VariableHREF contains variableQueryString then do something...
出于这个原因,我试图创建一个if语句来说,如果VariableHREF包含variableQueryString,那么做一些事......
if(variableHREF contains variableQueryString ){
$(this).closest('li').addClass('active');
}
I have that at the minute but it gives me a syntax error.
我现在有,但它给我一个语法错误。
1 个解决方案
#1
0
if(variableHREF.indexOf(variableQueryString) >= 0){
$(this).closest('li').addClass('active');
}
Should do the trick for you.
应该为你做的伎俩。
#1
0
if(variableHREF.indexOf(variableQueryString) >= 0){
$(this).closest('li').addClass('active');
}
Should do the trick for you.
应该为你做的伎俩。