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. 在虚拟机(VMware)中安装Linux CentOS 6.4系统(图解) 转

    一.下载最新版本Linux CentOS     1.打开官网地址:http://www.centos.org/,点击Downloads->Mirrors         2.点击CentOS ...

  2. LockSupport理解

    一.背景 在看并发包源码的时候看见过LockSupport,今天恰巧看到LockSupport字眼,于是看下jdk1.7中的源码结构.想着它应该是运用多线程的锁工具的,到底似乎怎么实现的呢? 二.使用 ...

  3. thinkPHP中_initialize方法实例分析

    子类的_initialize方法自动调用父类的_initialize方法. 而php的构造函数construct,如果要调用父类的方法,必须在子类构造函数显示调用parent::__construct ...

  4. Access是什么?

    一种使用简单的数据库软件,非常实用! 是微软的一个小型数据库,是Microsoft office 中的一个组件. Access数据库能够进行数据表设计.可视查询设计.SQL查询语言.窗体设计.报表设计 ...

  5. phpmailer的SMTP ERROR: Failed to connect to server: 10

    请问,我在win7上学习使用phpmailer时,出现这种错误怎么处理啊? SMTP ERROR: Failed to connect to server: (0) SMTP connect() fa ...

  6. Uva10129 - Play on Words 欧拉通路 DFS

    题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=105& ...

  7. react项目中遇到的坑

    1,touchStart和touchEnd 如果touchstart和touchend改变的是同一个state,那么在首次加载渲染的时候组件会陷入死循环,原因是touchstart会直接触发,但此时s ...

  8. 爬取知名社区技术文章_article_3

    爬虫主逻辑处理,获取字段,获取主url和子url #!/usr/bin/python3 # -*- coding: utf-8 -*- import scrapy from scrapy.http i ...

  9. linkin大话面向对象--接口

    接口(interface)的概念,掌握接口很重要,以后所有的编程都要面向接口编程.其实接口的内涵就7个字:规范和实现分离. 抽象类是从多个类中抽象出来的模板,若要将这种抽象进行得更彻底,就得用到一种特 ...

  10. 远程服务调用(RMI)

    模块概念的引入,是本框架的一大优势,而跨JVM的远程服务调用则是另一个最有价值的功能. <本地服务调用>一文中我们讲解了跨模块间的服务调用可以是这样的: ServiceHelper.inv ...