js 操作cookie

1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
4 <title>test</title>
5 <SCRIPT type=text/javascript>
6 function Set(Cookie_name)
7 {
8 var Then = new Date()
9 Then.setTime(Then.getTime() + 1*36000000 ) //小时
10 document.cookie = Cookie_name+"=true;expires="+ Then.toGMTString()
11 }
12 function Get(Cookie_name)
13 {
14 var cookieString = new String(document.cookie)
15 var cookieHeader = Cookie_name+"="
16 var beginPosition = cookieString.indexOf(cookieHeader)
17 //alert(beginPosition);
18 if (beginPosition != -1) //cookie已经设置值,应该 不显示提示框
19 {
20 alert(Cookie_name+"返回"+cookieString.substring(beginPosition + cookieHeader.length));
21 }
22 else //cookie没有设置值,应该显示提示框
23 {
24 alert("Cookie 未找到!");
25 }
26 }
27 function Move(Cookie_name)
28 {
29 document.cookie = Cookie_name+"=;expires=Fri, 02-Jan-1970 00:00:00 GMT";
30 }
31 </SCRIPT>
32 </head>
33
34 <body>
35 <INPUT onclick="Set('steven lu')" type=button value=设置cookie值>
36 <INPUT onclick="Get('steven lu')" type=button value=查看cookie值>
37 <INPUT onclick="Move('steven lu')" type=button value=清除cookie值>
38 </body>
39 </html>
40 </HTML>
posted @ 2011-05-30 12:03  ╰☆Everytime I try to flying  阅读(304)  评论(0编辑  收藏  举报