Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.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_Css_Styles_Persistence_Switch Statement - Fatal编程技术网

Jquery 如何在浏览站点时保持动态切换样式表?

Jquery 如何在浏览站点时保持动态切换样式表?,jquery,css,styles,persistence,switch-statement,Jquery,Css,Styles,Persistence,Switch Statement,我已经实现了一个通过jQuery切换样式表的解决方案: 以下是从上述网站复制和粘贴的准确代码: (function ($j) { switch_style = { onReady: function () { this.switch_style_click(); }, switch_style_click: function(){ $(".box").click(function(){ var id = $(th

我已经实现了一个通过jQuery切换样式表的解决方案:

以下是从上述网站复制和粘贴的准确代码:

(function ($j) {

  switch_style = {

    onReady: function () {      
      this.switch_style_click();
    },

    switch_style_click: function(){
    $(".box").click(function(){
        var id = $(this).attr("id");

        $("#switch_style").attr("href", id + ".css");           
    });
    },
  };

  $j().ready(function () {
      switch_style.onReady();
  });

})(jQuery);
前提是为样式表引用提供一个
id
(例如
#switch_style
)并在单击另一个元素时切换“href”属性

这非常有效,但当我在页面之间导航时,样式表将恢复为页面加载时显示的原始样式表

所以我的问题是:

在浏览站点时,如何使动态切换的样式表保持不变

PS

顺便说一句,我考虑过调整主内容区域以防止页面重新加载,我很想这样做,但还没有找到一个解决方案。我曾多次尝试实施以下解决方案,但都未能成功:


您可以将用户的样式表选择存储在cookie中,然后在页面更改时,如果您的服务器具有动态语言(如PHP),则使用该语言更改输出的样式表,如果没有,则使用jQuery读取它设置的cookie,并根据cookie值更改样式表