0

私はページの配列を持っています

var $pages = ["events", "template", "privacy", "terms", "mentor", "party", "getinvolved", "tools"];

私がやりたいことは

  if ( $body[0].id !== anyOfThePageInTheArray ) {
    //do something here
    });

彼らがいるページが配列内のページの1つではない場合、どうすればよいですか。

私は試しましたが.inArray.eachおそらく私はそれを間違っているか何かしていると思います。

4

3 に答える 3

2

試す:

if($pages.indexOf($body[0].id) == -1){
    //code here
}
于 2013-06-13T19:43:03.080 に答える
2

ネイティブは正常にArray.indexOf動作します:

if ($pages.indexOf($body[0].id) === -1) {
    // It's not in there
}

ただし、jQuery に固執する場合:

if ($.inArray($body[0].id, $pages) === -1) {
    // It's not in there
}
于 2013-06-13T19:43:32.713 に答える