<!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的更多相关文章

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

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

  2. cookie换肤功能

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

  3. Android QMUI实战:实现APP换肤功能,并自动适配手机深色模式

    Android换肤功能已不是什么新鲜事了,市面上有很多第三方的换肤库和实现方案. 之所以选择腾讯的QMUI库来演示APP的换肤功能,主要原因: 1.换肤功能的实现过程较简单.容易理解: 2.能轻松适配 ...

  4. JS实现网页换肤功能效果

    网页换肤的基本原理 使用 JS 切换对应的 CSS 样式表.例如hao123首页的右上方就有网页换肤功能.除了切换 CSS 样式表文件之外,通常的网页换肤还需要通过 Cookie 来记录用户之前更换过 ...

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

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

  6. Android 换肤功能的实现(Apk插件方式)

    一.概述 由于Android 没有提供一套统一的换肤机制,我猜可能是因为国外更注重功能和体验的原因 所以国内如果要做一个漂亮的换肤方案,需要自己去实现. 目前换肤的方法大概有三种方案: (1)把皮肤资 ...

  7. 基于webpack4+vue-cli3项目的换肤功能

    起因 最近因公司需求,需要实现主题换肤功能,不仅仅是颜色的更改,还需要包括图片,字体等文件等更换,因此在百度里各种实现方案后,决定根据scss+style-loader/useable做换肤. 项目开 ...

  8. 使用 css/less 动态更换主题色(换肤功能)

    前言 说起换肤功能,前端肯定不陌生,其实就是颜色值的更换,实现方式有很多,也各有优缺点 一.看需求是什么 一般来说换肤的需求分为两种: 1. 一种是几种可供选择的颜色/主题样式,进行选择切换,这种可供 ...

  9. 一种简单的实现:Android一键换肤功能

    现在的APP开发,通常会提供APP的换肤功能,网上流传的换肤代码和实现手段过于复杂,我把原作者的代码重新整理抽取出来,转换成Eclipse项目,重新整理成正确.可直接运行的项目. 代码运行结果如图. ...

随机推荐

  1. Android在一个APP中通过包名或类名启动另一个APP

    开发有时需要在一个应用中启动另一个应用,比如Launcher加载所有的已安装的程序的列表,当点击图标时可以启动另一个应用.一般我们知道了另一个应用的包名和MainActivity的名字之后便可以直接通 ...

  2. 转:sql SELECT时的with(nolock)选项说明

    I used to see my senior developers use WITH (NOLOCK) when querying in SQL Server and wonder why they ...

  3. 自行修改android.jar使其包含隐藏api

    1) 从指定版本的rom内获取到framework.jar 2) 解压framework.jar和android sdk内的android.jar 3) 将framework.jar解出来的东西拷到a ...

  4. UML用例图说明

    转自:http://www.360doc.com/content/10/1206/23/3123_75672033.shtml 前些时间参加了潘加宇老师的技术讲座,UML建模技术受益匪浅.我也把平时的 ...

  5. 试题公式解决方案--kindeditor集成jmeditor公式web编辑器

    最近在搞一套在线的考试系统,一直为即支持公式编辑又得支持各种附件上传.图片上传.视频音频上传.文字编辑 的web编辑器而犯愁.于是乎试着把 kindeditor和jmeditor集成一下,多了不说了直 ...

  6. chrome 开发人员工具

    JavaScript Beautifier JavaScript 文件在上线前一般都会压缩下,压缩的 JavaScript 几乎没有可读性,几乎无法设定断点.在 Scripts 面板下面有个 Pret ...

  7. 关于源码编译每次提示有错误 要make update-api

    最近编译newline的版本的时候..同事修改了andoid默认输入法为百度.这是系统自动提供的API,所以每次编译会提示 此时在编译源码生成SDK的过程中会出现这个问题:************** ...

  8. java中基本数据类型和C语言中基本数据类型转换

    java中 1 short = 2 byte 1 char  = 2 byte 1 int    = 4 byte 1 long = 8 byte C语言中 typedef unsigned char ...

  9. hibernate--多对一单向关联 (重点!!!)

    一个用户组包含多个用户, 每个用户属于一个组. 一个人可以有多个车, 每个车属于一个人. 一个人有很多梦想, 一个特定的梦想属于一个人. 错误做法: person里 有 personid, perso ...

  10. Servlet实现文件上传(深度)(二)

    1.首先我们定义struts.properties的文件上传中的规则如下 struts.action.extension=action  <!--以.action为我们提交的后缀名-->s ...