/*html*/
<input type="button" value="set" id="set"/>
<input type="button" value="get" id="get" />
<input type="button" value="det" id="det" />
/*js*/
function setCookie(name,value,day){
var date = new Date();
date.setDate(date.getDate()+day);
document.cookie = name+"="+escape(value)+((day==null)?"":";expires="+date.toGMTString());
}
function detCookie(name){
var date = new Date();
date.setTime(0);
document.cookie = name+"=v;expires="+date.toGMTString();
}
function getCookie(name){
var str = document.cookie;
var arr1 = str.split("; ");
for(var i=0; i<arr1.length; i++){
var arr2 = arr1[i].split("=");
if(arr2[0]==name){return unescape(arr2[1])}
}
return null;
}
document.getElementById("set").onclick = function(){
setCookie("name","yao")
setCookie("age","19 1")
}
document.getElementById("get").onclick = function(){
alert(getCookie("age"))
}
document.getElementById("det").onclick = function(){
detCookie("name")
}