如果Cookie值不存在多个IndexOf的jQuery

|| 我有一个用jQuery创建的cookie,名为“ testCookie \”。我想检查一下这些值是否不存在,如果它们不存在(或等于或小于-1),我想做点什么,下面的代码当前什么都不做,它假定代码是\甚至不在那里并且在if语句之后加载所有内容,而不管cookie的值如何,有什么想法吗?
if ($.cookie(\'testCookie\').indexOf(\'shopping\',\'pricegrabber\',\'nextag\',\'shopzilla\')<=-1) {
    
已邀请:
        
indexOf
函数一次只能输入一个字符串。为此,您需要在
if
语句中包含多个子句,并与
&&
联接:
if(cookieValue.indexOf(\'shopping\') == -1 && cookieValue.indexOf(\'pricegrabber\') == -1)
您可以将所有条件添加到该“ 2”语句中。
&&
表示\“ if this and this \”等。     
        
indexOf()
的语法如下:
[\'a\', \'b\', \'c\', \'d\'].indexOf(\'b\'); // returns 1
您可以使用jQuery的
.inArray()
方法:
$.inArray(\'b\', [\'a\',\'b\',\'c\',\'d\']); // returns 1
如果
$.cookie(\'testCookie\')
返回字符串,您可以像这样检查它:
if ([\'grabber\',\'nextag\',\'shopzilla\'].indexOf($.cookie(\'testCookie\')) == -1)  {
    // your code
}
要么
if ($.inArray($.cookie(\'testCookie\', [\'grabber\',\'nextag\',\'shopzilla\']) == -1) {
    // your code
}
    

要回复问题请先登录注册