您的位置:首页 > 产品设计 > UI/UE

easyui动态切换主题

2019-06-10 18:05 1581 查看

easyui换主题,并记录在cookie

首先将easyui的样式文件加入一个ID,这里命名为easyuiTheme,然后在样式文件下面加入一个JS文件

changeEasyuiTheme.js文件的内容是

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'); if ((′iframe′);if(iframe.length > 0) {
for ( var i = 0; i < $iframe.length; i++) {
var ifr = $iframe[i];
$(ifr).contents().find(’#easyuiTheme’).attr(‘href’, href);
}
}

KaTeX parse error: Expected 'EOF', got '}' at position 57: …xpires : 7 }); }̲; if (.cookie(‘easyuiThemeName’)) {
changeThemeFun($.cookie(‘easyuiThemeName’));
}

jquery.cookie.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;
};

使用的时候

changeThemeFun(‘default’);
changeThemeFun(‘gray’);

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: