Javascript 如何在此代码上实现jQuery cookies

Javascript 如何在此代码上实现jQuery cookies,javascript,jquery,cookies,slidetoggle,Javascript,Jquery,Cookies,Slidetoggle,我刚刚编写了这段代码,使用幻灯片通过按钮将框切换为隐藏/显示: jQuery("#button").click(function () { jQuery('#box').slideToggle('fast'); }); 我想在上面实现cookies,以记住盒子是隐藏的还是可见的。有人能给我介绍一下吗?有一个jQuery Cookie插件可用,它可以使读写Cookie变得更加容易和方便。以下是一个例子: // if the slider is visible, set the cooki

我刚刚编写了这段代码,使用幻灯片通过按钮将框切换为隐藏/显示:

jQuery("#button").click(function () {
    jQuery('#box').slideToggle('fast');
});

我想在上面实现cookies,以记住盒子是隐藏的还是可见的。有人能给我介绍一下吗?

有一个jQuery Cookie插件可用,它可以使读写Cookie变得更加容易和方便。以下是一个例子:

// if the slider is visible, set the cookie slider value to true
$.cookie('slider', 'visible', { expires: 7, path: '/' });
var sliderVisible = $.cookie('slider');
要读取该值,请使用以下示例:

// if the slider is visible, set the cookie slider value to true
$.cookie('slider', 'visible', { expires: 7, path: '/' });
var sliderVisible = $.cookie('slider');

有关更多信息,请访问

有一个jQuery Cookie插件可用,它将使读取和写入Cookie变得更加容易和方便。以下是一个例子:

// if the slider is visible, set the cookie slider value to true
$.cookie('slider', 'visible', { expires: 7, path: '/' });
var sliderVisible = $.cookie('slider');
要读取该值,请使用以下示例:

// if the slider is visible, set the cookie slider value to true
$.cookie('slider', 'visible', { expires: 7, path: '/' });
var sliderVisible = $.cookie('slider');

有关更多信息,请访问

我刚让它工作起来。我制作了两个按钮,这样每个状态上都有不同的按钮(即关闭和打开)

//这段代码定义了单击close按钮时发生的情况

jQuery('#button_close').click(function () {
      jQuery(this).hide(); //this hides the close button as the box is now closed
      jQuery('#box').slideUp('fast'); //hides the box
      jQuery('#button_open').show(); //shows the open button
      jQuery.cookie("openclose","closed", {expires: 365}); // sets cookie
      return false;
    });
//这段代码定义了单击“打开”按钮时发生的情况

jQuery("#button_open").click(function () {
      jQuery(this).hide(); //hides the open button as the box is now open
      jQuery('#box').slideDown('fast'); //shows the box
      jQuery('#button_close').show(); //shows the close button
      jQuery.cookie("openclose","open", {expires: 365}); //sets cookie
      return false;
    });
//现在神奇的部分出现了。此代码检查名为“openclose”的cookie是否具有“closed”值。如果是,则隐藏关闭按钮+方框,并显示打开按钮

    if(jQuery.cookie("openclose") == "closed") {
        jQuery("#button_close").hide();
        jQuery("#button_open").show();
        jQuery('#box').hide();
    };

我刚让它工作起来。我制作了两个按钮,这样每个状态上都有不同的按钮(即关闭和打开)

//这段代码定义了单击close按钮时发生的情况

jQuery('#button_close').click(function () {
      jQuery(this).hide(); //this hides the close button as the box is now closed
      jQuery('#box').slideUp('fast'); //hides the box
      jQuery('#button_open').show(); //shows the open button
      jQuery.cookie("openclose","closed", {expires: 365}); // sets cookie
      return false;
    });
//这段代码定义了单击“打开”按钮时发生的情况

jQuery("#button_open").click(function () {
      jQuery(this).hide(); //hides the open button as the box is now open
      jQuery('#box').slideDown('fast'); //shows the box
      jQuery('#button_close').show(); //shows the close button
      jQuery.cookie("openclose","open", {expires: 365}); //sets cookie
      return false;
    });
//现在神奇的部分出现了。此代码检查名为“openclose”的cookie是否具有“closed”值。如果是,则隐藏关闭按钮+方框,并显示打开按钮

    if(jQuery.cookie("openclose") == "closed") {
        jQuery("#button_close").hide();
        jQuery("#button_open").show();
        jQuery('#box').hide();
    };

谷歌搜索“javascript Cookie”我想使用jquery Cookie。检查此项你可能会发现它有用谷歌搜索“javascript Cookie”我想使用jquery Cookie。检查此项你可能会发现它有用Hi T,恭喜找到答案。很好的文档技巧!这是非常清楚和有益的+1嗨,恭喜你找到了答案。很好的文档技巧!这是非常清楚和有益的+1.