标签:js cookie
//保存cookie function addCookie(objName, objValue, exdays) { var str = objName + "=" + escape(objValue); //cookie的内容 cookieName = cookieValue // 为时不设定过期时间,浏览器关闭时cookie自动消失 if (exdays > 0) { var date = new Date(); date.setTime(date.getTime() + exdays*24*60*60*1000); str += "; expires=" + date.toGMTString(); } document.cookie = str; } //获得cookie function getCookie(cookieName) { // 获得所有的cookie var arrStr = document.cookie.split(";"); // 便利取得的cookie值 for ( var i = 0; i < arrStr.length; i++) { // 讲每一个cookie拆分 var temp = arrStr[i].split("="); // 如果cookie的name与传入的参数一直 if (temp[0] == cookieName) // 返回cookie的value return unescape(temp[1]); } } //清除cookie function clearCookie(name) { setCookie(name, "", -1); } //设置cookie function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; }
本文出自 “不羁的风” 博客,请务必保留此出处http://fengcl.blog.51cto.com/9961331/1718987
标签:js cookie
原文地址:http://fengcl.blog.51cto.com/9961331/1718987