/* * 获取cookie * */ getCookie: function(name){ var str = ‘‘; var cookies = document.cookie; var arrCookie = cookies.split(‘;‘); for(var i=0;i<arrCookie.length;i++){ var content = arrCookie[i].split(‘=‘); if(content[0].replace(/^\s+|\s+$/g,"") == name.replace(/^\s+|\s+$/g,"")){ str = decodeURI(content[1]); break; } } return str; }, /* * 写cookie * expiresHours 多少天过期 * */ setCookie: function(name,value,expiresHours,path){ if(cpm.isEmpty(path))path = ‘/‘; var cookieString = name + "=" + encodeURI(value) + ‘; path=‘+path; if(expiresHours > 0){ var date = new Date(); date.setTime(date.getTime() + expiresHours * 86400); cookieString = cookieString + "; expires=" + date.toGMTString(); } document.cookie = cookieString; },
记录一下,下次要用的时候就不用重新写了
时间: 2024-10-11 11:05:36