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. 解决无限 This file is indented with tabs instead of 4 spaces

    File -> Settings -> Editor -> Code Style -> Java -> Tabs and Indents -> Use tab ch ...

  2. DedeCMS首页调用缩略图为背景

    配合{dede:arclist}{/dede:arclist}标签使用,既可以实现把缩略图作为背景,另外还需要用到background-position这个标签,做好背景的定位. http://www ...

  3. 紧急求助!配置SMTP插件出错,SMTP connect() failed

    http://bbs.csdn.net/topics/390848222 我来挖个坟.我知道问题所在了,只要你们本地或服务器上环境中只要确保开启了php_openssl 跟 php_socket等扩展 ...

  4. sqlite效率探测

    在编译后当然就是使用sqlite,贸贸然去测试了一下创建数据库,插入数据,仅几条数据,发现,真不错的数据库,后来把数据量提高到10000的 时候,发现,怎么这么慢,后来自己都受不了,网上一查,原来是如 ...

  5. Python实现简易Web服务器

     1.请自行了解HTTP协议 http://www.cnblogs.com/reboot51/p/8358129.html(点击跳转) 2.创建Socket服务,监听指定IP和端口 3.以阻塞方式等待 ...

  6. J.U.C JMM. pipeline.指令重排序,happen-before(续)

    前面已经介绍硬件平台Cache Coherence问题和解决办法,下面来看看Java虚拟机平台的相关知识.硬件平台处理器,高速缓存,主存之间的交互关系如下: Java内存模型(JMM)         ...

  7. IO 异常:The Network Adapter could not establish the connection 怎么解决

    IO 异常:The Network Adapter could not establish the connection 怎么解决

  8. Linux日志轮循实现(shell)

    在Linux系统中,日志的使用非常频繁,那么对日志就需要一定策略的管理,包括存放目录的设计,log文件命名规则,历史log文件的存放,log目录的容量限制,另外还有日志轮循. 日志轮循就是,将过期的l ...

  9. python编程理念

    在python控制台输入import this之后输出如下: The Zen of Python, by Tim PetersBeautiful is better than ugly.Explici ...

  10. sqlserver存储过程及mybatis调用——待续

    创建带输入参数存储过程 use yanantestgoif exists (select * from sys.objects where name='yanan')drop procedure ya ...