【问题标题】:jQuery/HTML Changing and saving plugin optionsjQuery/HTML 更改和保存插件选项
【发布时间】:2014-07-30 08:08:53
【问题描述】:

我正在使用jQuery Shapeshift plugin

插件有一个选项gutterX: 'some value'

我也在容器上启动插件:

$(".container").shapeshift();

我可以按如下方式更改选项:

$(".container").shapeshift({
    gutterX:20
});

但是我怎样才能将这个选项的值保存在 localstorage/cookie 中,这样即使浏览器被刷新,这个值也会被保留。

【问题讨论】:

标签: javascript jquery html plugins jquery-plugins


【解决方案1】:
var tempgutterX = 20;

//GET
$(".container").shapeshift();
if(localStorage.getItem("gutterX"))
{
    $(".container").shapeshift({ gutterX: localStorage.getItem("gutterX") });
}
else
{
    $(".container").shapeshift({ gutterX: tempgutterX });

    //SET for later
    localStorage.setItem("gutterX", tempgutterX);
}

使用 localstorage 如果它已经存储,它将从 localstorage 设置,否则它将存储下一次。 您可能还想先检查浏览器是否支持本地存储。

【讨论】:

    猜你喜欢
    • 2011-05-15
    • 1970-01-01
    • 2012-03-12
    • 2013-03-25
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多