admin管理员组文章数量:1287613
I'm using the following to do somting when url contains gender=men&dir=
if(window.location.href.indexOf("gender=men&dir=") > -1) {
}
Now i need to say url contains gender=men&dir= and not &dir=Schoenen do something
i was trying this only its not working
if(window.location.href.indexOf("gender=men&dir=" || !"&dir=Schoenen") > -1) {
}
I'm using the following to do somting when url contains gender=men&dir=
if(window.location.href.indexOf("gender=men&dir=") > -1) {
}
Now i need to say url contains gender=men&dir= and not &dir=Schoenen do something
i was trying this only its not working
if(window.location.href.indexOf("gender=men&dir=" || !"&dir=Schoenen") > -1) {
}
Share
Improve this question
asked Jan 23, 2013 at 1:05
IvoIvo
2,6366 gold badges27 silver badges43 bronze badges
0
2 Answers
Reset to default 6You have to call indexOf
twice:
var hasGender = window.location.href.indexOf("gender=men&dir=") != -1;
var hasDir = window.location.href.indexOf("&dir=Schoenen") != -1;
if ( hasGender && ! hasDir ) {
// Do whatever you want...
}
||
can't be used that way.
You need to state the window.location.href.indexOf
twice:
if (window.location.href.indexOf("gender=men&dir=") > -1) &&
window.location.href.indexOf("&dir=Schoenen") == -1) {
}
// > -1 is if found
// == -1 is if not found
If you want to change the AND (&&
) into an OR (||
), you'll need to replace &&
into ||
.
本文标签: Javascript windowlocationhrefindexOf is A and not BStack Overflow
版权声明:本文标题:Javascript window.location.href.indexOf is A and not B - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741316623a2371952.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论