js 操作 cookie

  
<HTML>
 <HEAD>
  <TITLE> js & cookie demo </TITLE>
 
  <SCRIPT LANGUAGE="JavaScript">
  <!--
		 function setcookie(name,value){
			var Days = 30;
			var exp  = new Date();
			exp.setTime(exp.getTime() + Days*24*60*60*1000);
			document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
		}

		function getcookie(name){
			var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); 
			if(arr != null){
				return unescape(arr[2]);
			}else{
				return "";
			}
		}

		function delcookie(name){
			var exp = new Date(); 
			exp.setTime(exp.getTime() - 1);
			var cval=getcookie(name);
			if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
		}
 
		if (document.cookie != "") { 
			setcookie("GD-cms", "gae-django-cms");
		}
	    //-->
  </SCRIPT>
 </HEAD>

 <BODY>
<INPUT onclick="setcookie('姓名1','刘德华')" type=button value=设置cookie值1><br> 
<INPUT onclick="setcookie('姓名2','张学友')" type=button value=设置cookie值2><br><br> 

<INPUT onclick="alert(getcookie('姓名1'))" type=button value=查看cookie值1><br> 
<INPUT onclick="alert(getcookie('姓名2'))" type=button value=查看cookie值2><br><br>

<INPUT onclick="delcookie('姓名2')" type=button value=清除cookie值2> 
 </BODY>
</HTML>

你可能感兴趣的:(html,cms,django,GAE)