cookie记忆换肤功能实战Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery换肤+cookie记忆功能</title>
<link rel="stylesheet" href="../css/style.css" media="screen" />
<link rel="stylesheet" href="../css/reset.css" media="screen" />
<link rel="stylesheet" href="../css/green.css" media="screen" name="skin" />
<script src="../jquery-1.10.2.min.js"></script>
<script src="../jquery.cookie.js"></script>
</head>
<body>
<div id="wrapper">
<h1>jQuery Playground</h1>
<div id="stylechange" class="clear">
<ul>
<li><a href="javascript:void(0)" class="green"></a></li>
<li><a href="javascript:void(0)" class="blue"></a></li>
</ul>
</div>
<ul id="nav">
<li><a href="index.html" class="current">测试</a></li>
<li><a href="#">关于</a></li>
</ul>
<div id="content">
<h2>WelCome!</h2>
<p>Hello,everyone.I will share some useful tips of jQuery here.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div id="footer">Powered By Dennis Ji.</div>
</div>
</body>
<script>
$(function(){
var favstyle = readCookie('style');//style是cookie的名字
console.log(favstyle);//../css/green.css上次定义的绿色或蓝色皮肤在这里得到了输出
if(favstyle){
$("link[name='skin']").attr({href:favstyle});
}
//绿色主题
$(".green").click(function(){
$("link[name='skin']").attr({href:"../css/green.css"});
createCookie('style',"../css/green.css",365);
});
//蓝色主题
$(".blue").click(function(){
$("link[name='skin']").attr({href:"../css/blue.css"});
createCookie('style',"../css/blue.css",365);
});
//下面是jQuery版本(注意:要写在$(function(){})里面)的的创建、读取、删除cookie
function createCookie(name,value,days){
var expires;
if (days) {
expires = days;
} else{
expires = "";
}
$.cookie(name,value,{expires:expires,path:'/'});
}
function readCookie(name){
var styles = $.cookie(name);//jQuery的cookie只用这样写就能读出cookie的值了
return styles;
}
function delCookie(name){
$.cookie(name,null)
}
//注:本地cookie的读取要用localhost才能读取,普通的无服务器的文件路径是读取不到的
});
</script>
</html>
cookie记忆换肤功能实战Demo的更多相关文章
- 用js来实现页面的换肤功能(带cookie记忆)
用js来实现页面的换肤功能 js实现换肤功能的实现主要是通过利用js控制CSS来实现的.大致的实现原理是这样的, 1.先定义一个页面基本样式style.css来确定div的宽高等属性,使得整个页面的D ...
- cookie换肤功能
<div class="selectSkin"> <input id="red" class="themeBtn" typ ...
- Android QMUI实战:实现APP换肤功能,并自动适配手机深色模式
Android换肤功能已不是什么新鲜事了,市面上有很多第三方的换肤库和实现方案. 之所以选择腾讯的QMUI库来演示APP的换肤功能,主要原因: 1.换肤功能的实现过程较简单.容易理解: 2.能轻松适配 ...
- JS实现网页换肤功能效果
网页换肤的基本原理 使用 JS 切换对应的 CSS 样式表.例如hao123首页的右上方就有网页换肤功能.除了切换 CSS 样式表文件之外,通常的网页换肤还需要通过 Cookie 来记录用户之前更换过 ...
- 【转】Javascript+css 实现网页换肤功能
来源:http://www.php100.com/html/webkaifa/DIV_CSS/2008/1014/2326.html Html代码部分: 1.要有一个带id的样式表链接,我们要通过操作 ...
- Android 换肤功能的实现(Apk插件方式)
一.概述 由于Android 没有提供一套统一的换肤机制,我猜可能是因为国外更注重功能和体验的原因 所以国内如果要做一个漂亮的换肤方案,需要自己去实现. 目前换肤的方法大概有三种方案: (1)把皮肤资 ...
- 基于webpack4+vue-cli3项目的换肤功能
起因 最近因公司需求,需要实现主题换肤功能,不仅仅是颜色的更改,还需要包括图片,字体等文件等更换,因此在百度里各种实现方案后,决定根据scss+style-loader/useable做换肤. 项目开 ...
- 使用 css/less 动态更换主题色(换肤功能)
前言 说起换肤功能,前端肯定不陌生,其实就是颜色值的更换,实现方式有很多,也各有优缺点 一.看需求是什么 一般来说换肤的需求分为两种: 1. 一种是几种可供选择的颜色/主题样式,进行选择切换,这种可供 ...
- 一种简单的实现:Android一键换肤功能
现在的APP开发,通常会提供APP的换肤功能,网上流传的换肤代码和实现手段过于复杂,我把原作者的代码重新整理抽取出来,转换成Eclipse项目,重新整理成正确.可直接运行的项目. 代码运行结果如图. ...
随机推荐
- js动态添加file控件
<html></head><script language="javascript" type="text/ecmascript" ...
- git查看每个版本间的差异
命令行: 1,git log: 2,git diff 版本号码 窗口类型: 1,sudo apt-get install gitk 2,gitk
- 笔记:利用Cocos2dx 3.3 lua 做一个动作类游戏(一)
在这之前,声明一下: 做不完我是小狗. 没办法,没毅力和恒心,之前的那个Quick Cocos2dx做的横版过关游戏的demo已经转成了3.3的版本了,其实也算是个半成品,战斗,UI啥的都有了,呵呵. ...
- Protocol buffers--python 实践(一) 简介以及安装与使用
由于最近对grpc产生了浓厚的兴趣,但是那是一整套东西,看了一下用到的东西不少,所以抽丝剥茧先写写这几天调研的protocol buffer -python的收获. 简介: 以下引用自官方首页文档: ...
- UWSGI配置文件---ini和xml示例
一 conf.ini文件: [uwsgi] http = $(HOSTNAME):9033 http-keepalive = 1 pythonpath = ../ module = service ...
- Hibernate---第一个helloworld程序 (XML版本, annotation版本)
Hibernate作为JPA的一种实现,jpa的注解已经是hibernate的核心,hibernate只提供了一些补充,而不是两套注解.hibernate对jpa的支持够足量,在使用hibernate ...
- IOS中集合视图UICollectionView中DecorationView的简易使用方法
转载自: http://www.it165.net/pro/html/201312/8575.html Decoration View是UICollectionView的装饰视图.苹果官方给的案例 ...
- iOS平台软件开发工具(一)-新建的工程使用CocoaPods工具集成第三方框架
CocoaPods是一款集合了上千个第三方开源库的开发工具,能够大幅度的提升团队项目的开发效率,降低时间成本. 那么就看一下CocoaPods这个工具在项目中的使用体现吧. 我们马上用ASIHTTPR ...
- HMM 隐马尔科夫模型
参考如下博客: http://www.52nlp.cn/itenyh%E7%89%88-%E7%94%A8hmm%E5%81%9A%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8 ...
- AVR单片机的BOOT区
BOOT区的由来基于一个简单的道理,即单片机的程序是保存在FLASH中的,要运行程序就必须不停的访问FLASH存储器.对于一般的FLASH存储器,数据的写入需要一定的时间来完成,在数据写入完成之前,存 ...