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>换肤&nbsp;<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 换肤的更多相关文章

  1. cookie换肤功能

    <div class="selectSkin"> <input id="red" class="themeBtn" typ ...

  2. cookie记忆换肤功能实战Demo

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  3. 用js来实现页面的换肤功能(带cookie记忆)

    用js来实现页面的换肤功能 js实现换肤功能的实现主要是通过利用js控制CSS来实现的.大致的实现原理是这样的, 1.先定义一个页面基本样式style.css来确定div的宽高等属性,使得整个页面的D ...

  4. 网页换肤,模块换肤,jQuery的Cookie插件使用(转)

    具体效果如下: 第一次加载如下图: 然后点击天蓝色按钮换成天蓝色皮肤如下图: 然后关闭网页重新打开或者在打开另一个网页如下图: 因为皮肤用Cookie保存了下来,所以不会重置 具体的实现代码如下: & ...

  5. jquery.cookie中的操作之与换肤

    jquery.cookie.js的插件,插件的源代码如下: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) ...

  6. 锋利的jQuery-5--网页换肤

    网页换肤原理:通过调用不同的样式表文件来实现不同的皮肤,并且将切换好的皮肤计入cookie. 例子:通过点击上边的颜色设置下边显示的背景色. html代码: <!-- head部分引入的css样 ...

  7. 【转】Javascript+css 实现网页换肤功能

    来源:http://www.php100.com/html/webkaifa/DIV_CSS/2008/1014/2326.html Html代码部分: 1.要有一个带id的样式表链接,我们要通过操作 ...

  8. js实现换肤效果

    一,js换肤的基本原理 基本原理很简单,就是使用 JS 切换对应的 CSS 样式表文件.例如导航网站 Hao123 的右上方就有网页换肤功能.除了切换 CSS 样式表文件之外,通常的网页换肤还需要通过 ...

  9. Android App插件式换肤实现方案

    背景 目前很多app都具有换肤功能,用户可以根据需要切换不同的皮肤,为使我们的App支持换肤功能,给用户提供更好的体验,在这里对换肤原理进行研究总结,并选择一个合适的换肤解决方案. 换肤介绍 App换 ...

随机推荐

  1. 13.第一个只出现一次的字符[FindFirstNotRepeatingChar]

    [题目] 在一个字符串中找到第一个只出现一次的字符.如输入abaccdeff,则输出b. [分析] 这道题是2006年google的一道笔试题. 看到这道题时,最直观的想法是从头开始扫描这个字符串中的 ...

  2. C++ 通过WIN32 API 获取逻辑磁盘详细信息

    众所周知,在微软的操作系统下编写应用程序,最主要的还是通过windows所提供的api函数来实现各种操作的,这些函数通常是可以直接使用的,只要包含windows.h这个头文件, 下载源文件 今天我们主 ...

  3. delphi提示“Undeclared_identifier”的缺少引用单元列表

    _Stream ADODB_TLB akTop, akLeft, akRight, akBottom Controls Application (the variable not a type) Fo ...

  4. excel复制+粘贴,怎样让公式里的参数不自动变化?

    例如,某一单元格内容为:=A1+A2 我把它复制+粘贴到其他地方,就自动变成了:=B1+B2 怎样让它不变化,仍保持=A1+A2 ?? 答: Excel一般使用相对地址来引用单元格的位置,当把一个含有 ...

  5. 【JAVA、C++】 LeetCode 008 String to Integer (atoi)

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  6. 读取STL模型

    读取二进制格式的STL模型文件 std::ifstream fin;fin.open(stlFilePath, std::ios::in | std::ios::binary);bool isBina ...

  7. Andoird自定义ViewGroup实现竖向引导界面

    一般进入APP都有欢迎界面,基本都是水平滚动的,今天和大家分享一个垂直滚动的例子. 先来看看效果把: 首先是布局文件: <com.example.verticallinearlayout.Ver ...

  8. MVC中session创建并获取问题

    有两个ActionResult分别为A和B,如下 public ActionResult A() { Session["test"]="123"; return ...

  9. 把notepad++设置为系统全局文本默认打开应用

    notepad++: 设置-->首选项-->文件关联->customize: 可以设置的常见默认打开文件后缀格式有:.log,.txt,.ini,.h,.c,.cpp,.java,. ...

  10. DRF如何序列化外键的字段

    我觉得在有些应用场景下,这个操作是有用的,因为可以减少一个AJAX的请求,以增加性能. 当然,是二次请求,还是一次传输.这即要考虑用户体验,还要兼顾服务器性能. 一切是有条件的平衡吧.就算是一次传输, ...