标签:style blog io color ar 使用 sp for div
function cookie(name,value,expires){ switch(typeof value){ case ‘string‘: //设置 var exp=‘‘; if(expires){ var oDate=new Date(); oDate.setDate(oDate.getDate()+expires); exp=‘;expires=‘+oDate.toUTCString(); } document.cookie=name+‘=‘+encodeURIComponent(value)+exp; break; case ‘undefined‘: //获取 if(document.cookie){ var arr=document.cookie.split(‘; ‘), aLen=arr.length, nLen=name.length; for(var i=0; i<aLen; i++){ if(arr[i].substring(0,nLen)==name){ return decodeURIComponent(arr[i].substring(nLen+1)); } } } break; default: //删除 arguments.callee(name,‘1‘,-1); } }
使用方法:
cookie(‘username‘,‘wei\n魏...‘,14); //设置cookie,14天后cookie删除 cookie(‘username‘,‘wei‘); //设置cookie,浏览器关闭时cookie删除 cookie(‘age‘,‘21‘); //设置cookie,注意用引号把数字变成字符串 cookie(‘username‘); //获取cookie cookie(‘username‘,null); //删除cookie
标签:style blog io color ar 使用 sp for div
原文地址:http://www.cnblogs.com/aiweidong/p/4095600.html