cookie 换肤
jquery.Cookies.js
/**
* Cookie plugin
*
* Copyright (c) 2006 ziqiu.zhang
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* 使用举例:
//注: 写入时,subName参数请传递空值或null
//写入Cookies-值为字符串,即不包含子键
$.cookie("singleKey", "", "singleKey-value", { expires: 1, path: "/", secure: false })
//读取Cookies-根据主键
alert("singleKey:" + $.cookie("singleKey")); //写入Cookies-值为对象,则每个属性名为子键的名称,属性值为子键值
var subNameObj = { subName1: "aaa", subName2: "bbb", subName3: "ccc" };
$.cookie("multiKey", "", subNameObj, { expires: 1, path: "/", secure: false });
//读取Cookies-根据主键
alert("multiKey:" + $.cookie("multiKey"));
//读取Cookies-根据主键和子键
alert("multiKey,subName1:" + $.cookie("multiKey", "subName1"));
*
*/ jQuery.cookie = function(name, subName, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : ';path=/';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : ''; //If value is an object, each property will be a sub key;
if (typeof value == "object") {
var k = 0;
var tempResult = "";
for (var tempValue in value) {
if (k > 0) {
tempResult += "&";
}
tempResult += tempValue + "=" + encodeURIComponent(value[tempValue]);
k++;
}
value = tempResult;
} else {
value = encodeURIComponent(value);
} document.cookie = [name, '=', value, expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); //Search sub key
if (typeof subName != 'undefined' && subName != null && subName != "") {
var subCookies = cookieValue.toString().split('&');
for (var j = 0; j < subCookies.length; j++) {
var subCookie = jQuery.trim(subCookies[j]);
if (subCookie.substring(0, subName.length + 1) == (subName + '=')) {
cookieValue = decodeURIComponent(subCookie.substring(subName.length + 1));
break;
}
}
} break;
} }
}
return cookieValue;
}
};
<script type="text/javascript" src="/themes/admin/js/jquery.Cookies.js"></script>
<span><strong class="fl pr" id="colorcsshf"><em class="hticons hticons-hf"></em>换肤 <em class="colorcss defaultcss" onclick="changeTheme('');"></em><em class="colorcss bluecss" onclick="changeTheme('blue');"></em><em class="colorcss greencss" onclick="changeTheme('green');"></em><em class="colorcss yellowcss" onclick="changeTheme('yellow');"></em><em class="colorcss graycss" onclick="changeTheme('gray');"></em></strong><strong class="fl"><em class="hticons hticons-yh"></em>
function getCookie(c_name) {
if (document.cookie.length > 0) { //先查询cookie是否为空,为空就return ""
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end));
}
}
return "";
}
function setCookie(c_name, value, expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
function loadCss(className, isIframeMenu) {
var container = document;
if (isIframeMenu) {
container = window.frames["ifrmenu"].document;
}
var cssTag = container.getElementById('loadCss');
var head = container.getElementsByTagName('head').item(0);
if (cssTag) head.removeChild(cssTag);
if (className != '') {
css = container.createElement('link');
css.href = '/themes/admin/css/' + className + '.css';
css.rel = 'stylesheet';
css.type = 'text/css';
css.id = 'loadCss';
head.appendChild(css);
}
}
function loadIframeCss(className) {
var cssTag = window.frames["ifrmenu"].document.getElementById('loadCss');
var head = window.frames["ifrmenu"].document.getElementsByTagName('head').item(0);
if (cssTag) head.removeChild(cssTag);
if (className != '') {
css = window.frames["ifrmenu"].document.createElement('link');
css.href = '/themes/admin/css/' + className + '.css';
css.rel = 'stylesheet';
css.type = 'text/css';
css.id = 'loadCss';
head.appendChild(css);
}
}
function changeTheme(className) {
$.cookie('theme', '', className, { expires: 365, path: "/login", secure: false });
$.cookie('theme', '', className, { expires: 365, path: "/", secure: false });
loadCss(className);
loadCss(className,true);
}
blue.css/gray.css/green.css/yellow.css
cookie 换肤的更多相关文章
- cookie换肤功能
<div class="selectSkin"> <input id="red" class="themeBtn" typ ...
- cookie记忆换肤功能实战Demo
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- 用js来实现页面的换肤功能(带cookie记忆)
用js来实现页面的换肤功能 js实现换肤功能的实现主要是通过利用js控制CSS来实现的.大致的实现原理是这样的, 1.先定义一个页面基本样式style.css来确定div的宽高等属性,使得整个页面的D ...
- 网页换肤,模块换肤,jQuery的Cookie插件使用(转)
具体效果如下: 第一次加载如下图: 然后点击天蓝色按钮换成天蓝色皮肤如下图: 然后关闭网页重新打开或者在打开另一个网页如下图: 因为皮肤用Cookie保存了下来,所以不会重置 具体的实现代码如下: & ...
- jquery.cookie中的操作之与换肤
jquery.cookie.js的插件,插件的源代码如下: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) ...
- 锋利的jQuery-5--网页换肤
网页换肤原理:通过调用不同的样式表文件来实现不同的皮肤,并且将切换好的皮肤计入cookie. 例子:通过点击上边的颜色设置下边显示的背景色. html代码: <!-- head部分引入的css样 ...
- 【转】Javascript+css 实现网页换肤功能
来源:http://www.php100.com/html/webkaifa/DIV_CSS/2008/1014/2326.html Html代码部分: 1.要有一个带id的样式表链接,我们要通过操作 ...
- js实现换肤效果
一,js换肤的基本原理 基本原理很简单,就是使用 JS 切换对应的 CSS 样式表文件.例如导航网站 Hao123 的右上方就有网页换肤功能.除了切换 CSS 样式表文件之外,通常的网页换肤还需要通过 ...
- Android App插件式换肤实现方案
背景 目前很多app都具有换肤功能,用户可以根据需要切换不同的皮肤,为使我们的App支持换肤功能,给用户提供更好的体验,在这里对换肤原理进行研究总结,并选择一个合适的换肤解决方案. 换肤介绍 App换 ...
随机推荐
- maven项目,导入的jar包,没有包含在pom文件中,install失败
[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[ ...
- 70 数组的Kmin算法和二叉搜索树的Kmin算法对比
[本文链接] http://www.cnblogs.com/hellogiser/p/kmin-of-array-vs-kmin-of-bst.html [分析] 数组的Kmin算法和二叉搜索树的Km ...
- c++11之bind
std::bind是个c++推出的新的特性,非常有用,让你写起来率试不爽. #include <iostream> using namespace std; #include <fu ...
- zpf 命名规则
2014年8月19日 18:48:39 所有控制器都要继承main类,main类是一个入口类,他里边根据请求初始化了一些变量,也初始化了一些系统变量等等,这些变量和函数可以被控制器类直接使用 控制器类 ...
- PHP 调试用函数
2014年7月4日 10:27:59 有些系统函数可以在调试程序时救急用: get_class_methods(); get_class_vars(); get_object_vars(); get_ ...
- MFC LIST 获取行数和列数
DWORD dwStyle = dataListControl.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与 ...
- 在Win8中创建热点,共享网络
在Win8中创建热点,共享网络 办公室中,我独享10M光纤,没什么要下的,便想利用来更新下Ipad里面的程序,下点公开课.那在不利用软件[用很多wifi共享的软件],从win7开始 系统本身就自带相关 ...
- glut编译问题 (程序无法运行)
参考:http://blog.csdn.net/robinjwong/article/details/5636049 error: the procedure entry point _glutini ...
- Java关于队列的自我实现
1.循环队列的封装 package com.pinjia.shop.common.collection; /** * Created by wangwei on 2016/12/29. * 循环队列的 ...
- KMP模式匹配_2
http://blog.csdn.net/lin_bei/article/details/1252686 三. 怎么求串的模式值next[n] 定义: (1)next[0]= -1 意义:任何串的第一 ...