Posted in Javascript onOctober 03, 2012
javascript操作cookie简单版本
function setCookie(name, value, iDay) { var oDate = new Date(); oDate.setDate(oDate.getDate() + iDay); document.cookie = name+'='+value+';expires='+oDate; } function getCookie(name) { var arr = document.cookie.split('; '); var i = 0; for(i=0; i<arr.length; i++) { var arr2 = arr[i].split('='); if(arr2[0] == name) {return arr2[1];} } return ''; } function removeCookie(name) { setCookie(name,'',-1); }
javascript操作cookie封装版本
var cookie=new function(){ this.set=function(name,value,hours){ var life=new Date().getTime(); life+=hours*1000*60; var cookieStr=name+"="+escape(value)+";expires="+new Date(life).toGMTString(); document.cookie=cookieStr; }; this.get=function(name){ var cookies = document.cookie.split(";"); if(cookies.length>0){ var cookie=cookies[0].split("="); if(cookie[0]==name) {return unescape(cookie[1]);} } return null; }; this.remove=function(name){ var cookieStr=name+"="+escape('null')+";expires="+new Date().toGMTString(); document.cookie=cookieStr; }; }
留着备用吧
Javascript操作cookie的函数代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@