將使用者個人化儲存到用戶端

來源:互聯網
上載者:User

(一).樣本圖片效果

(二).代碼
<html>
<head>
<title>Cookie</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#6699ff" text="#000000">
<script language="javascript">
function getcookie()
{
if (document.cookie==null)
{
document.bgColor="black"
document.fgcolor="white"
}
else
{
var x1=unescape(document.cookie)
var x2=x1.split("; ")
for (i in x2)
{
var x3=x2[i].split("=");
var x4=x3[0];
switch (x4)
{
case "setcolor":
document.fgColor=x3[1]
break;
case "setbgcolor":
document.bgColor=x3[1]
break;
}
}
}
}
getcookie()
var setcolor="white";
var setbgcolor="black";
function setcookie()
{
x1=document.form1.select1.options.selectedIndex
switch (x1)
{
case 0:
setcolor="white";
setbgcolor="black";
break;
case 1:
setcolor="black";
setbgcolor="white";
break;
case 2:
setcolor="red";
setbgcolor="yellow";
break;
case 3:
setcolor="yellow";
setbgcolor="red";
break;
case 4:
setcolor="white";
setbgcolor="blue";
break;
}
var webcookie ="setcolor="+setcolor+";setbgcolor="+setbgcolor;
var date1=new Date();
date1.setYear(date1.getYear()+1);
cookiedate =date1.toGMTString();
document.cookie ="setcolor="+escape(setcolor)+";expires="+date1.toGMTString()+";path=/";
document.cookie ="setbgcolor="+escape(setbgcolor)+";expires="+date1.toGMTString()+";path=/";
getcookie()
}
</script>
<form name=form1>
選擇配色:<select name=select1 size=1 onChange="setcookie()">
<option value=1 style="color:white;background-color:black">黑白色配置</option>
<option value=2 style="color:black;background-color:white">白黑色配置</option>
<option value=3 style="color:red;background-color:yellow">黃紅色配置</option>
<option value=4 style="color:yellow;background-color:red">紅黃色配置</option>
<option value=5 style="color:white;background-color:blue">藍白色配置</option>
</select>
</form>
</body>
</html>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.