欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery通過寫入cookie實(shí)現(xiàn)更換網(wǎng)頁背景的方法

 更新時間:2016年04月15日 09:27:52   作者:懶人  
這篇文章主要介紹了jQuery通過寫入cookie實(shí)現(xiàn)更換網(wǎng)頁背景的方法,涉及jQuery結(jié)合cookie設(shè)置頁面元素屬性的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了jQuery通過寫入cookie實(shí)現(xiàn)更換網(wǎng)頁背景的方法。分享給大家供大家參考,具體如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery更換網(wǎng)頁背景(寫入cookie)</title>
<style type="text/css">
 body,p,ul{margin:0;padding:0;}
 ul{float:right;height:40px;margin-top: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 #cccc;top:0;left:0;width:100%;}
 .red{background:#F06;}/*紅色*/
 .black{background:#000;}/*黑色*/
 .blue{background:#09F;}/*藍(lán)色*/
 .green{background:#093;}/*綠色*/
</style>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
   //為了安全 google chrome 等瀏覽器是禁止本地文件寫Cookie的即file:///F:/Lord%20community/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");//保存當(dāng)前選擇的類名
       $("body").attr("class",className,30);//把選中的類名給body
       function SetCookie(name,value,day)//兩個參數(shù),一個是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函數(shù)  
   {
    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>

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery的cookie操作技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》、《jquery選擇器用法總結(jié)》及《jQuery常用插件及用法總結(jié)

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論