-1) { -6ren">
gpt4 book ai didi

Javascript window.location.href.indexOf 是 A 而不是 B

转载 作者:行者123 更新时间:2023-12-01 14:19:23 25 4
gpt4 key购买 nike

当 url 包含 gender=men&dir= 时,我正在使用以下内容进行排序

if(window.location.href.indexOf("gender=men&dir=") > -1) {

}

现在我需要说 url 包含 gender=men&dir= 而不是 &dir=Schoenen do something

我试过这个只是它不起作用

if(window.location.href.indexOf("gender=men&dir=" || !"&dir=Schoenen") > -1) {

}

最佳答案

你必须调用 indexOf 两次:

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...
}

关于Javascript window.location.href.indexOf 是 A 而不是 B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14470836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com