<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用js设置cookie,并能读取</title>
</head>
<body>
<!--script>
function getCookie(str){
var tmp,reg=new RegExp("(^| )"+str+"=([^;]*)(;|$)","gi");
if(tmp=reg.exec(document.cookie))return(tmp[2]);
return null;
}
var arr=["a","b","c"]
var arr2=["d","e","f"]
document.cookie="username=" + arr;
document.cookie="password=" + arr2;
if(arr=getCookie("username").split(","))alert(arr[1]);
if(arr=getCookie("password").split(","))alert(arr[1]);
</script-->
<script>
var NO=4;
var ArrayStr=new Array();for(i=0;i<NO;i++)ArrayStr[i]="null";
function AddArray(str,gor){
ArrayStr[gor-1]=str;
document.cookie="username="+ArrayStr;
}
function getCookie(str){
var tmp,reg=new RegExp("(^| )"+str+"=([^;]*)(;|$)","gi");
if(tmp=reg.exec(document.cookie))return(tmp[2]);
return null;
}
function ReadCookie(){
alert(getCookie("username").split(","));
}
</script>
<input type="button" onclick="AddArray(value,sing)" value="题目一" sing="1">
<input type="button" onclick="AddArray(value,sing)" value="题目二" sing="2">
<input type="button" onclick="AddArray(value,sing)" value="题目一" sing="3">
<input type="button" onclick="AddArray(value,sing)" value="题目二" sing="4">
<input type="button" value="查看答案" onclick="ReadCookie()">
</body>
</html>