检查多个cookie jQuery语法

我想检查是否设置了两个cookie中的一个:

if($.cookie("c1") != 'true' || $.cookie("c2") != 'true') { 

(然后根据cookie做一些动作,或设置cookie)

这是检查第一个还是第二个是否设置的正确语法?

谢谢。

正确的语法是

 if($.cookie("c1") !== null || $.cookie("c2") !== null) { // one of the cookies, or both, are set } else { // none of the cookies are set } 

从你的评论中 ,你所追求的可能是:

 if($.cookie("c1") !== null && $.cookie("c2") !== null) { // both cookies exist, let's check if they have the values we need if($.cookie("c1") === "true" && $.cookie("c2") === "true") { // they have 'true' as their content } else { // they might exist, but both do not hold the value 'true' } } else { // none, or at least one of the two cookies are not set }