(一).示例图片效果
(二).代码
<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>