cookie函数封装

时间:2022-05-09 19:57:05
 var  cookieUtil = {
setCookie :function (cname, cvalue, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate()+exdays);
var expires =exdays?"expires="+exdate.toUTCString():"";
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/;domain=.uborm.com.cn;";
}, getCookie:function (cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}, clearCookie:function (name) {
setCookie(name, "", -1);
}
}