Home > Article > Web Front-end > 3 commonly used default functions (library) for JScookie
JScookie 3 commonly used default functions (library)
nbsp;HTML><meta><title>无标题文档</title><script>function setCookie(name, value, iDay) //iday是多少天后过期 {var oDate=new Date(); oDate.setDate(oDate.getDate()+iDay); document.cookie=name+'='+value+';expires='+oDate;} //黄色的等号其实是添加不是赋值的意思. 重复添加不会覆盖//设置需要有过期的概念, 不设置会即时过期.function getCookie(name) {var arr=document.cookie.split('; '); for(var i=0;i<arr.length;i++) {var arr2=arr[i].split('=');</script>
//cookie的存储形式是 user= zhangsan, =是:的意思,split'=' 切割cookie完成查找功能if(arr2[0]==name) {return arr2[1]; } } return ''; }function removeCookie(name) { setCookie(name, 1, -1); //设置过期为-1天, 就是删除了cookies, 实际上0也可以.}removeCookie('password'); alert(document.cookie);
Remember user name
The above is the detailed content of 3 commonly used default functions (library) for JScookie. For more information, please follow other related articles on the PHP Chinese website!