2

URLにgender=men&dir =が含まれている場合、私は以下を使用してsomtingを実行しています

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

      }

ここで、URLにはgender = men&dir =が含まれ、&dir=Schoenenは何かを実行しないと言う必要があります

私はこれを試していましたが、機能していません

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

      }
4

2 に答える 2

6

あなたは二度電話しなければなりません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...
}
于 2013-01-23T01:09:29.203 に答える
2

||そのように使用することはできません。

あなたは二度述べる必要がありますwindow.location.href.indexOf

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

AND(&&)をOR(||)に変更する場合は、に置き換える必要があり&&ます||

于 2013-05-27T15:35:39.237 に答える