zoukankan      html  css  js  c++  java
  • easyui换主题,并记录在cookie

    注:引入JS的顺序jquery>cookie>easyuicss>changeEasyUITheme.js
    首先将easyui的样式文件加入一个ID,这里命名为easyuiTheme,然后在样式文件下面加入一个JS文件
    1 <script type="text/javascript" charset="UTF-8" src="jslib/jquery-easyui-1.2.5/jquery-1.7.1.min.js"></script>
    2 
    3 <script type="text/javascript" charset="UTF-8" src="jslib/jquery.cookie.js"></script>
    4 
    5 <link id="easyuiTheme" rel="stylesheet" type="text/css" href="jslib/jquery-easyui-1.2.5/themes/gray/easyui.css">
    6 <script type="text/javascript" charset="UTF-8" src="jslib/changeEasyuiTheme.js"></script>
    7 <link rel="stylesheet" type="text/css" href="jslib/jquery-easyui-1.2.5/themes/icon.css">
    8 <script type="text/javascript" charset="UTF-8" src="jslib/jquery-easyui-1.2.5/jquery.easyui.min.js"></script>
    9 <script type="text/javascript" charset="UTF-8" src="jslib/jquery-easyui-1.2.5/locale/easyui-lang-zh_CN.js"></script>

    changeEasyuiTheme.js文件的内容是

     1 function changeThemeFun(themeName) {/* 更换主题 */
     2     var $easyuiTheme = $('#easyuiTheme');
     3     var url = $easyuiTheme.attr('href');
     4     var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';
     5     $easyuiTheme.attr('href', href);
     6 
     7     var $iframe = $('iframe');
     8     if ($iframe.length > 0) {
     9         for ( var i = 0; i < $iframe.length; i++) {
    10             var ifr = $iframe[i];
    11             $(ifr).contents().find('#easyuiTheme').attr('href', href);
    12         }
    13     }
    14 
    15     $.cookie('easyuiThemeName', themeName, {
    16         expires : 7
    17     });
    18 };
    19 if ($.cookie('easyuiThemeName')) {
    20     changeThemeFun($.cookie('easyuiThemeName'));
    21 }

    jquery.cookie.js的内容是

     1 jQuery.cookie = function (key, value, options) {
     2 
     3     // key and value given, set cookie...
     4     if (arguments.length > 1 && (value === null || typeof value !== "object")) {
     5         options = jQuery.extend({}, options);
     6 
     7         if (value === null) {
     8             options.expires = -1;
     9         }
    10 
    11         if (typeof options.expires === 'number') {
    12             var days = options.expires, t = options.expires = new Date();
    13             t.setDate(t.getDate() + days);
    14         }
    15 
    16         return (document.cookie = [
    17             encodeURIComponent(key), '=',
    18             options.raw ? String(value) : encodeURIComponent(String(value)),
    19             options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
    20             options.path ? '; path=' + options.path : '',
    21             options.domain ? '; domain=' + options.domain : '',
    22             options.secure ? '; secure' : ''
    23         ].join(''));
    24     }
    25 
    26     // key and possibly options given, get cookie...
    27     options = value || {};
    28     var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    29     return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
    30 };

    使用的时候

    changeThemeFun('default');
    changeThemeFun('gray');

     

     

     

  • 相关阅读:
    学习也好,科研也罢,都有内在规律。任何事物,只消抓住规律,就等于牵住牛鼻子
    赵伟国:陆资无法进入台湾紫光要到WTO控告(芯片是为了经济安全,高通找的人不是很聪明)
    小米新旗舰“翻车” 冲击中高端凸显品控短板(小米的缺点还真不少:电商、性价比、爆款、粉丝经济,说到底也都只是商业上的创新)
    WinRarHelper帮助类
    Window7下安装Ubuntu 14.04 64bit
    Kafka基本原理
    Abot爬虫和visjs
    CLR垃圾回收的设计
    NET Core全新的配置管理
    Github Atom
  • 原文地址:https://www.cnblogs.com/easyteck/p/2570790.html
Copyright © 2011-2022 走看看