EasyUI实现更换主题能过样式添加id实现,将原来的样式值添加到cookie中保存,这样下次浏览器访问时,就是我们原来选择的样式!

首先将easyui的样式文件加入一个ID,这里命名为easyuiTheme,然后在样式文件下面加入一个JS文件
 
 
 
<link href="Static/EasyUI/themes/default/menu.css" rel="stylesheet" type="text/css" />
    <script src="Static/EasyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="Static/EasyUI/jquery.cookie.js" type="text/javascript"></script>
    <link href="Static/EasyUI/themes/default/easyui.css" rel="stylesheet" type="text/css"  id="easyuiTheme" />  <%--此id用于改变皮肤方法--%>
    <script src="Static/EasyUI/changeEasyuiTheme.js" type="text/javascript"></script>
    <link href="Static/EasyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="Static/EasyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="Static/EasyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="Static/CommonJS/ty.baseExtend.methods.js" type="text/javascript"></script>
9

changeEasyuiTheme.js文件的内容是
01 function changeThemeFun(themeName) {/* 更换主题 */
02     var $easyuiTheme = $('#easyuiTheme');
03     var url = $easyuiTheme.attr('href');
04     var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';
05     $easyuiTheme.attr('href', href);
06  
07     var $iframe = $('iframe');
08     if ($iframe.length > 0) {
09         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的内容是
01 jQuery.cookie = function (key, value, options) {
02  
03     // key and value given, set cookie...
04     if (arguments.length > 1 && (value === null || typeof value !== "object")) {
05         options = jQuery.extend({}, options);
06  
07         if (value === null) {
08             options.expires = -1;
09         }
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 };

使用的时候
1 changeThemeFun('default');
2 changeThemeFun('gray');

EasyUI实现更换主题能过样式添加id实现的更多相关文章

  1. 怎么为WebStorm更换主题 修改字体样式

    这篇文章主要用于帮助大家解决怎么为webstorm换theme. 首先,到选择一个自己喜欢的皮肤,Webstorm皮肤网址: http://phpstorm-themes.com/ 然后,选中你喜欢的 ...

  2. easyui更换主题之后出现validatebox的验证提示信息显示跑偏的解决方案

    在easyui中更换主题为非default的主题,有的主题会出现如下图所示的情况,验证提示信息的提示内容跑到了下面. 现在说下原因和解决方案: 原因:原因是easyui对某些主题没有进行这个样式的设置 ...

  3. PhpStorm 8.x/9.x 快捷键设置/个性化设置,如何多项目共存?如何更换主题?

    1."自定义"常用快捷键(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> ...

  4. ASP.NET加载主题和皮肤样式的各种方式

    一.加载主题(皮肤.样式表)的多种方式 除了在页面指令中采用Theme或者StylesheetTheme为单个页面加载主题外,还可以通过配置文件为多个页面批量加载主题,另外,还可以通过改变页面的The ...

  5. github+hexo搭建自己的博客网站(二)更换主题yilia

    开始更换主题,hexo默认的主题是landscape,可以更换为其他的主题yilia主题 详细的可以查看hexo博客的演示:saucxs.github.io 可以查看在github上生成的静态文件:h ...

  6. PhpStorm快捷键设置/个性化设置,如何多项目共存?如何更换主题?

    #常用快捷键  设置快捷键:File -> Settings -> IDE Settings -> Keymap -> 选择“Eclipse” -> 然后“Copy”一份 ...

  7. 使用 css/less 动态更换主题色(换肤功能)

    前言 说起换肤功能,前端肯定不陌生,其实就是颜色值的更换,实现方式有很多,也各有优缺点 一.看需求是什么 一般来说换肤的需求分为两种: 1. 一种是几种可供选择的颜色/主题样式,进行选择切换,这种可供 ...

  8. Intellij Idea更换主题

    <h1 class="title">Intellij Idea更换主题</h1> <!-- 作者区域 --> <div class=&qu ...

  9. Html-IOS下input的样式添加不上的解决方案

    问题描述: <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml&qu ...

随机推荐

  1. 基于Echarts4.0实现旭日图

    昨天Echarts4.0正式发布,随着4.0而来的是一系列的更新,挑几个主要的简单说明: 1.展示方面通过增量渲染技术(4.0+)ECharts 能够展现千万级的数据量 2.针对移动端优化,移动端小屏 ...

  2. Sqoop导入导出的几个例子

    Sqoop导入导出的几个例子 http://sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html#_importing_data_into_hive   no ...

  3. 邓_PPT

    如何拯救一份丑到爆的PPT? "小邓,这是我做的PPT,你优化优化,明天早上给我,上午客户来要用." 领导,你这是PPT嘛,明明就是word嘛. "小张啊,你看看我这个P ...

  4. angular 选中切换面板

    此方法采用的是没有路由的方式: html5 代码: <div [hidden]="flag"> <li class="music-list-datail ...

  5. java中的按位与运算

    package scanner; public class SingleAnd { public static void main(String[] args) { int[] first = {10 ...

  6. isinstance和issubclass、动态模块导入、异常处理

    一.isinstance和issubclass isinstance:判断某个对象是否是某个类的实例,返回True或Flase issubclass:判断某个类是否是某个类的子类. 例如: class ...

  7. mysql主从同步(3)-percona-toolkit工具(数据一致性监测、延迟监控)使用梳理

    转自:http://www.cnblogs.com/kevingrace/p/6261091.html 在mysql工作中接触最多的就是mysql replication mysql在复制方面还是会有 ...

  8. mybatis-databaseIdProvider多数据库支持

    <select id="selectPerson" parameterType="int" parameterMap="deprecated&q ...

  9. ECLIPS-S测井系统下的仪器挂接 [CV模块]

    常见简写 简写 全拼 含义 CV Calibration and Verification 刻度和校验 CP Primary Calibration 主刻度 VP Primary Verify 主校验 ...

  10. Python Django连接(听明白了是连接不是创建!)Mysql已存在的数据库

    再声明一次!是连接不是创建!网上的一些人难道连接和创建这俩词都弄不懂就在那里瞎写一些文章! (Python Django连接存在的数据库) Python连接存在的数据库-------MySql 1.首 ...