检查多个cookie jQuery语法 [英] Check multiple cookies jQuery syntax

查看:95
本文介绍了检查多个cookie jQuery语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查是否设置了两个Cookie之一:

I'd like to check if one of the two cookies are set:

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

(然后取决于cookie做一些动作,或设置cookie)

(and then depending on the cookie do some action, or set cookie)

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

Is this the proper syntax to check if either the first or the second are set?

感谢。

推荐答案

正确的语法是

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

}

这篇关于检查多个cookie jQuery语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆