H5-cookie封装函数


 1 /* 设置cookie函数 */
 2 function setCookie(key,value,day) {
 3     var date=new Date();
 4     date.setDate(date.getDate()+day);
 5     document.cookie=key+'='+escape(value)+';expires='+date;
 6 }
 7 /* 获取cookie函数 */
 8 function getCookie(key) {
 9     var coo=unescape(document.cookie);//解码
10     var arr1=coo.split('; ');//第一次分解后是数组
11     for (var i=0;i<arr1.length;i++){//第二次循环拆分数组
12         var arr2=arr1[i].split('=');
13         if(arr2[0]==key){
14             return arr2[1];
15         }
16     }
17 }
18 /* 删除cookie */
19 function removeCookie(key) {
20     setCookie(key,'',-1);
21 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM