-1

有人可以在此代码上添加 cookie 吗?这是一个主题转换器..:P

$(function () {
    $("ul.rightside").prepend('<div id="nav_background">Colors</div>');
    $(".minwidth_IE").prepend('<div id="toggle_background" style="display: none;"><div id="navigation_popup_close" class="popupClose clickable"><img src="http://i81.servimg.com/u/f81/18/07/42/17/close_11.png" alt="x"></div><div id="custom_background"><span id="bg0"></span><span id="bg1"></span><span id="bg2"></span><span id="bg3"></span><span id="bg4"></span><span id="bg5"></span><span id="bg7"></span><span id="bg8"></span></div></div>');
    $("#custom_background span").click(function () {
        $("#account ,.minwidth_IE ,.main .main-head ,#fa_toolbar").removeClass("bg1 bg2 bg3 bg4 bg5 bg7 bg8 bg_custom").addClass($(this).attr("id"));
    });
    $("#custom_submit").click(function () {
        var b = $("#custom_input").val();
        $("#account ,.minwidth_IE ,.main .main-head ,#fa_toolbar").removeClass("bg1 bg2 bg3 bg4 bg5 bg7 bg8 bg_custom").addClass("bg_custom").css("background-image", "url('" + b + "')");
    });
    $("#nav_background").click(function () {
        $("#toggle_background").slideToggle();
    });
    $("#navigation_popup_close").click(function() {
   $("#toggle_background").fadeOut();
});

 $("#custom_background span").click(function () {
        $("#vbar").removeClass("bg1 bg2 bg3 bg4 bg5 bg7 bg8 bg_custom bg11 bg21 bg31 bg41 bg51 bg71 bg81").addClass($(this).attr("id")+ (+1));
    });
    $("#custom_submit").click(function () {
        var b = $("#custom_input").val();
        $("#vbar").removeClass("bg11 bg21 bg31 bg41 bg51 bg71 bg81 bg_custom2").addClass("bg_custom2").css("background-image", "url('" + b + "')");
    });

$("#custom_background span").click(function () {
        $("#tbar").removeClass("bg1 bg2 bg3 bg4 bg5 bg7 bg8 bg_custom bg12 bg22 bg32 bg42 bg52 bg72 bg82").addClass($(this).attr("id")+ (+2));
    });
    $("#custom_submit").click(function () {
        var b = $("#custom_input").val();
        $("#tbar").removeClass("bg12 bg22 bg32 bg42 bg52 bg72 bg82 bg_custom3").addClass("bg_custom3").css("background-image", "url('" + b + "')");
    });

 $("#bg0").click(function(){
 $("#account ,.minwidth_IE ,.main .main-head ,#fa_toolbar").removeClass("bg1 bg2 bg3 bg4 bg5 bg7 bg8 bg_custom");
  $("#vbar").removeClass("bg11 bg21 bg31 bg41 bg51 bg71 bg81 bg_custom2");
  $("#tbar").removeClass("bg12 bg22 bg32 bg42 bg52 bg72 bg82 bg_custom3");
});
});

希望有人知道如何在没有任何错误的情况下添加此代码 cookie。再一次非常感谢你!

4

1 回答 1

0

有一个名为 jQuery 的插件,jquery.cookie它使使用 cookie 变得轻而易举。

您只需要下载插件并将其包含在以下行中:

<script src="/path/to/jquery.cookie.js"></script>

然后像这样使用它:

设置 cookie

$.cookie('the_cookie', 'the_value');

读取 cookie

var theValue = $.cookie('the_cookie');

有关更多信息,请参阅: https ://github.com/carhartl/jquery-cookie#readme

于 2013-10-12T11:10:59.400 回答