- // 封装设置 cookie 方法
- function setCookie(key, value, t) {
- var oDate = new Date();
- oDate.setDate(oDate. () + t);
- document.cookie = key + '=' + value + ';expires=' + oDate.toGMTString();
- }
- // 封装按 key 读取 cookie 的方法
- function getCookie(key) {
- var arr1 = document.cookie.split(';');
- for(car i = 0; i < arr1.lrngth; i++) {
- var arr2 = arr[i].split('=');
- if(arr2[0] == key){
- return decodeURL(arr2[1]);
- }
- }
- }
- // 封装删除 cookie
- function removeCookie(key) {
- setCookie(key, '', -1);
- }
来源: http://www.qdfuns.com/article/40690/516c4aee3d0575170aa80f1f6267bfaa.html