Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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 使用jCookie存储CSS字体大小_Jquery_Css - Fatal编程技术网

Jquery 使用jCookie存储CSS字体大小

Jquery 使用jCookie存储CSS字体大小,jquery,css,Jquery,Css,我目前正在尝试在我的网站顶部创建三个链接,当点击锚时,链接会改变主体字体大小,然后使用jCookie存储,这样当用户返回页面时,字体大小保持在所选大小 以下是我已经拥有的: 我的链接: <ul id="fonts"> <li><a href="#" id="normal" rel="100%">Normal</a></li> <li><a href="#" id="large" rel="110%"&

我目前正在尝试在我的网站顶部创建三个链接,当点击锚时,链接会改变主体字体大小,然后使用jCookie存储,这样当用户返回页面时,字体大小保持在所选大小

以下是我已经拥有的: 我的链接:

<ul id="fonts">
    <li><a href="#" id="normal" rel="100%">Normal</a></li>
    <li><a href="#" id="large"  rel="110%">Large</a></li>
    <li><a href="#" id="largest"rel="120%">Largest</a></li>
</ul>
我正在检查变量“font”是否已保存在会话中,如果已保存,则更改主体的css以将字体大小更改为该存储变量。我以前已经让它工作过,但这次似乎有问题。 有人能解释一下吗?
非常感谢

元素#all在$(document).ready()之外可能未就绪。。。因此,您应该将这些行移到$(document).ready()方法中。当然可以!谢谢!:)
  jQuery(document).ready(function(){    
       if(jQuery.cookie("font")) {
          jQuery("#all").css("font-size", jQuery.cookie("font"));
       }

       jQuery('#csschange li a').click(function() {
          jQuery("link.changeme").attr("href", jQuery(this).attr('rel'));
             jQuery.cookie("css",jQuery(this).attr('rel'), {expires: 365, path: '/'});
                    return false;
          });
       });
   });