首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >类的jQuery切换并切换cookie值?

类的jQuery切换并切换cookie值?
EN

Stack Overflow用户
提问于 2011-07-28 18:08:43
回答 2查看 883关注 0票数 0

有可能像下面的例子那样切换cookie吗?我以前有两个按钮,但是我只想用一个按钮来切换。

代码语言:javascript
运行
复制
$("#text-change").click(function() {
    $("body").toggleClass("large");
    $(this).toggleClass("large");

    // Here I want to toggle the cookie value
    $.cookie("textSize", "large", {expires: 365});
    $.cookie("textSize", "small", {expires: 365});

    return false;
});

//then I can the check cookie throughout the site
if($.cookie("textSize") != "large") {
    $("#text-smaller").addClass("disabled");
    $("body").removeClass("large");
}
else {
    $("#text-larger").addClass("disabled");
    $("body").addClass("large");
}
EN

回答 2

Stack Overflow用户

发布于 2011-07-28 18:12:29

代码语言:javascript
运行
复制
$("#text-change").click(function() {
    $("body").toggleClass("large");
    $(this).toggleClass("large");

    // Here I want to toggle the cookie value
    if ($(this).hasClass("large")){
        $.cookie("textSize", "large", {expires: 365});
    }else{
        $.cookie("textSize", "small", {expires: 365});
    }

    return false;
});
票数 0
EN

Stack Overflow用户

发布于 2011-07-28 18:21:50

更简单

代码语言:javascript
运行
复制
$("#text-change").click(function() {
    $("body").add(this).toggleClass("large");

    // Here I want to toggle the cookie value
    $.cookie("textSize", $(this).hasClass("large")?"large":"small", {expires: 365});

    return false;
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6863619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档