function writeCookie() {
var today = new Date();
today.setDate(today.getDate() + 1);
document.cookie = 'userName=商商;Expires=' + today.toGMTString();//js进行设置过期时间时,只支持这种日期转码
}
function readyCookie() {
var cookie = document.cookie;
alert(cookie);
var array = cookie.split(';');
for (var item in array)
{
var array1 = array[item].split('=');
for (var item1 in array1)
{
if (array1[item1] = 'userName')
{
// alert(array1[item1]);
alert(array1[0]);
//return;
}
}
}
}
</script>
</head>
<body>
<input id="Button1" type="button" value="写入Cookie" onclick="writeCookie()" />
<input id="Button2" type="button" value="读出Cookie" onclick="readyCookie()" />
</body>
</html>