如何用javascript读cookie
想在客户端直接读cookie,并判断跟一个变量是否相等,不经过服务器端,javascript能不能实现,如何实现?
[CODE]<html>
<head>
<title>读写cookies</title>
</head>
<body>
<script language="javascript">
document.cookie="a=a;"
document.cookie="b=b;"
var mycookie = document.cookie;
function readcookie(name)
{
var start1 = mycookie.indexOf(name + "=");
if (start1== -1)
alert("cookies not found");
else
{
start=mycookie.indexOf("=",start1)+1;
var end = mycookie.indexOf(";",start);
if (end==-1)
{
end=mycookie.length;}
var value=unescape(mycookie.substring(start,end));
if (value==null)
{alert("No cookies found!");}
else
{alert("cookie变量:"+name+" 的值是 :"+value);}
}
}
readcookie("a");
readcookie("b");
</script>
</body>
</html>
[/CODE]