zoukankan      html  css  js  c++  java
  • 转:基于jquery点击切换样式并且可以记忆cookie

    这个网页特效基于jquery的样式切换jquery插件,点击按钮链接切换样式并且可以记忆cookie的jquery插件styleswitch.js,没有清除cookie的情况下他会一直保持上一次的选择状态。

    必须在 head 区域引用 jquery.min.js 和styleswitch.js 示例如下:
     <script type="text/javascript" src="jquery.min.js"></script>
     <script type="text/javascript" src="styleswitch.js"></script>

    要切换的样式自己设置。

    你可以自行配置 styleswitch.js 中的设置或者增加功能

    (function($)
    {
     $(document).ready(function() {
      $('.styleswitch').click(function()
      {
       switchStylestyle(this.getAttribute("rel"));
       return false;
      });
      var c = readCookie('style');
      if (c) switchStylestyle(c);
     });

     function switchStylestyle(styleName)
     {
      $('link[@rel*=style][title]').each(function(i)
      {
       this.disabled = true;
       if (this.getAttribute('title') == styleName) this.disabled = false;
      });
      createCookie('style', styleName, 365);
     }
    })(jQuery);
    // cookie functions http://www.quirksmode.org/js/cookies.html
    function createCookie(name,value,days)
    {
     if (days)
     {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
     }
     else var expires = "";
     document.cookie = name+"="+value+expires+"; path=/";
    }
    function readCookie(name)
    {
     var nameEQ = name + "=";
     var ca = document.cookie.split(';');
     for(var i=0;i < ca.length;i++)
     {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
     }
     return null;
    }
    function eraseCookie(name)
    {
     createCookie(name,"",-1);
    }
    // /cookie functions
     

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    SpringBoot启动项目时提示:Error:java: 读取***.jar时出错;
    K8S操作
    二、kubernetes搭建集群
    三、Json方式函数
    一、Gulp
    大萨达所
    三、IIS通过目录方式部署以供外部调试
    四、附加到进程调试(.NET Framework)
    一、bootstrap-fontawesome-iconpicker组件
    表单
  • 原文地址:https://www.cnblogs.com/tracy/p/1768373.html
Copyright © 2011-2022 走看看