easyui 更换皮肤

  easyui 的主题文件存在themes文件夹中,默认显示default的显示样式,这里我们希望实现easyui的自动换肤,并在cookie中将此样式保存一段时间(7天),解决方案如下:

  1> 将皮肤的样式文件引入到当前的主界面中,并为其添加一个id:easyuiTheme

<script src="../easyUI/jquery-2.0.3.js" type="text/javascript"></script>
    <script src="../easyUI/jquery.cookies.js" type="text/javascript"></script>
    <script src="../easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <link href="../easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <link id="easyuiTheme" href="../easyUI/themes/gray/easyui.css" rel="stylesheet" type="text/css" />

  2> 更改主题方法

function changeThemeFun(themeName) {/* 更换主题 */
            var $easyuiTheme = $(‘#easyuiTheme‘);
            var url = $easyuiTheme.attr(‘href‘);
            var href = url.substring(0, url.indexOf(‘themes‘)) + ‘themes/‘ + themeName + ‘/easyui.css‘;
            $easyuiTheme.attr(‘href‘, href);

            var $iframe = $(‘iframe‘);
            if ($iframe.length > 0) {
                for (var i = 0; i < $iframe.length; i++) {
                    var ifr = $iframe[i];
                    $(ifr).contents().find(‘#easyuiTheme‘).attr(‘href‘, href);
                }
            }

            $.cookie(‘easyuiThemeName‘, themeName, {
                expires: 7
            });
        };

  3> jquery.cookies.js文件

jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === ‘number‘) {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), ‘=‘,
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? ‘; expires=‘ + options.expires.toUTCString() : ‘‘, // use expires attribute, max-age is not supported by IE
            options.path ? ‘; path=‘ + options.path : ‘‘,
            options.domain ? ‘; domain=‘ + options.domain : ‘‘,
            options.secure ? ‘; secure‘ : ‘‘
        ].join(‘‘));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp(‘(?:^|; )‘ + encodeURIComponent(key) + ‘=([^;]*)‘).exec(document.cookie)) ? decode(result[1]) : null;
};

  4> 页面初始化的时候设置一个默认的主题

$(function () {
            if ($.cookie(‘easyuiThemeName‘)) {
                changeThemeFun($.cookie(‘easyuiThemeName‘));
            }
        });

  5> 方法调用如下:

 <div id="menu" class="easyui-menu" style="width:120px; display:none">
           <div onclick="changeThemeFun(‘gray‘)" >Gray</div>
            <div onclick="changeThemeFun(‘black‘)" >Black</div>
             <div onclick="changeThemeFun(‘default‘)" >Default</div>
        </div>

引用:

http://www.jeasyuicn.com/post-64.html

时间: 2024-08-29 12:13:10

easyui 更换皮肤的相关文章

visual studio 2012更换皮肤、功能添加

首先在vs2012的菜单:工具->扩展和更新,打开扩展和更新窗口,点击左侧“联机”,搜索栏里面输入Theme Editor.然后点击按钮,安装之后,在工具->选项->环境常规 面板上面颜色主题下拉框,就可以选择换肤了.附图 visual studio 2012更换皮肤.功能添加

apk分享: Android应用更换皮肤功能的实现思路教程。

Android 的发展确实太快了,每年的都有很多新东西出现,想要覆盖所有新东西感觉也不太可能,我这里主要说一下主要的 Android 的主要新技术发展,其实了解 Android 的发展趋势,可能对开发者更有帮助. 开发工具 Android Studio: Google 官方放弃 Eclipse 和 Android Studio 普及.AS 虽然不算新,但是对 Android Studio 这个软件的更新速度快的惊人,有大量的新功能发布.例如支持很多注解代码提示注解.Live code templ

Android更换皮肤解决方案

Android更换皮肤解决方案 转载请注明出处:IT_xiao小巫 本篇博客要给大家分享的一个关于Android应用换肤的Demo,大家可以到我的github去下载demo,以后博文涉及到的代码均会上传到github中统一管理. github地址:https://github.com/devilWwj/Android-skin-update 思路 换肤功能一般有什么? 元素一般有背景颜色.字体颜色.图片.布局等等 我们知道Android中有主题Theme还有style,theme是针对整个act

WinForm 使用皮肤,且单击按更换皮肤。

运行效果: 首先把DLL程序集文件和SSK皮肤文件放在要运行程序的DEBug文件夹下,然后引入引用. 之后可以在程序里写代码了. 1 private void Form2_Load(object sender, EventArgs e) 2 { 3 //方法-01(使用全路径) 4 skinEngine1.SkinFile = @"E:\桌面文件\App_Test\App_Test\bin\Debug\DeepCyan.ssk"; 5 6 //方法-02 7 Sunisoft.Iris

android 简单的更换皮肤

更换皮肤 1.更换皮肤其实就是更换Activity的背景图片 直接上代码: Activity: 1 public class MainActivity extends Activity implements OnClickListener { 2 3 private SkinManager skinManager; 4 private int downNums; 5 private Button btn; 6 7 @Override 8 protected void onCreate(Bundl

Qt 利用Qss更换皮肤

1.不同的皮肤配置写在不同的.qss文件. 2.在main加载默认的皮肤文件 #include "mainwindow.h" #include <QApplication> #include <QFile> int main(int argc, char *argv[]) { QApplication a(argc, argv); QFile qss_file(":/default.qss"); if(!qss_file.open(QFile

怎样给 VS 更换皮肤

微软的 Visual Studio 是目前最为流行的编程工具.在新版的 Visual Studio 中,提供了三种皮肤可供大家选择.那么,到底怎样给 Visual Studio 更换皮肤呢? 工具/原料 Visaul Studio 方法: 启动 Visual Studio.   点击菜单“工具”-“选项”.   在打开的选项窗口中,在左侧选择“环境”-“常规”.   此时,选择右侧“视觉体验”一项下不同的颜色主题,即可调整 Visual Studio 的皮肤外观.   下面是选择浅色皮肤后的界面

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

在easyui中更换主题为非default的主题,有的主题会出现如下图所示的情况,验证提示信息的提示内容跑到了下面. 现在说下原因和解决方案: 原因:原因是easyui对某些主题没有进行这个样式的设置,导致这个验证信息会到处跑. 首先,通过firebug可以看到出现上面问题的jsp页面有如下图的html,这段html内容就是提示信息所在的html,可以找到下面的class="validatebox-tip-content"的span,之所以出现验证提示信息乱跑的情况的原因是easyui

EasyUI更换主题

EasyUI默认的主题有几个 EasyUI的使用需要导入 <script type="text/javascript" src="/resources/js/lib/easyui/jquery.min.js"></script> <script type="text/javascript" src="/resources/js/lib/easyui/jquery.easyui.min.js">