jQuery通过写入cookie实现更换网页背景的方法
网络编程 2021-07-04 21:04www.168986.cn编程入门
这篇文章主要介绍了jQuery通过写入cookie实现更换网页背景的方法,涉及jQuery结合cookie设置页面元素属性的相关操作技巧,需要的朋友可以参考下
本文实例讲述了jQuery通过写入cookie实现更换网页背景的方法。分享给大家供大家参考,具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://.w3./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery更换网页背景(写入cookie)</title> <style type="text/css"> body,p,ul{margin:0;padding:0;} ul{float:right;height:40px;margin-:20px;margin-right:20px;} ul li{list-style-type:none;float:left;width:20px;height:20px;margin-left:10px;cursor:pointer;} .skin{height:40px;position:fixed;background:#fff;border-bottom:solid 1px #;:0;left:0;width:100%;} .red{background:#F06;}/*红色*/ .black{background:#000;}/*黑色*/ .blue{background:#09F;}/*蓝色*/ .green{background:#093;}/*绿色*/ </style> <script type="text/javascript" src="http://lib.sinaapp./js/jquery/1.8.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ //为了安全 google chrome 等浏览器是禁止本地文件写Cookie的即file:///F:/Lord%20munity/lrtk/Untitled-2.html这样的以file开头的是不能写本地文件的 var cookieClass = getCookie('class');//读取需要缓存的对象。 $("body").attr("class",cookieClass);// $(".skin_list li").each(function(){ $(this).click(function(){ var className=$(this).attr("class");//保存当前选择的类名 $("body").attr("class",className,30);//把选中的类名给body function SetCookie(name,value,day)//两个参数,一个是cookie的名子,一个是值 { var exp = new Date(); //new Date("December 31, 9998"); exp.setTime(exp.getTime() + day*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } SetCookie("class",className,30); }) }); }); function getCookie(name)//取cookies函数 { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } </script> </head> <body> <div class="skin"><ul class="skin_list"><li style="width:100px;text-align:right;">更换背景:</li></li><li class="red"></li><li class="black"></li><li class="blue"></li><li class="green"></li></ul></div> </body> </html>
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家jQuery程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程