Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 保存更改的背景_Jquery_Cookies_Background_Addclass - Fatal编程技术网

Jquery 保存更改的背景

Jquery 保存更改的背景,jquery,cookies,background,addclass,Jquery,Cookies,Background,Addclass,我编写了一段代码,只需单击一个按钮即可更改body类,但问题是这些更改在刷新页面时不会保存 更改类时如何保存这些设置 这是我的代码: var classes = ['mystics','steampunk', 'love', 'ny', 'olympic', 'pirates']; var count = 0; $(function() { $('#bgChange').click(function(e){ count ++; e.preventDef

我编写了一段代码,只需单击一个按钮即可更改body类,但问题是这些更改在刷新页面时不会保存

更改类时如何保存这些设置

这是我的代码:

var classes = ['mystics','steampunk', 'love', 'ny', 'olympic', 'pirates'];
var count = 0;
$(function() {  
    $('#bgChange').click(function(e){
        count ++;
        e.preventDefault();
        $('body').addClass(classes[teller]);
    });
});

刷新页面时,DOM会被重新加载,因此任何早期的更改都会丢失,即使刷新页面,也可以使用HTML5本地存储或会话存储来记住更改