1 获取cookie 2 function getCookie(name){ 3 var cookie = document.cookie; 4 var cookies = cookie.split(';'); 5 //把数组转换成对象 6 var cookieObj = {}; 7 for(var i = 0; i < cookies.length; i++){ 8 var _obj = cookies[i].split('='); 9 cookieObj[_obj[0]] = _obj[1]
JS设置cookie,删除cookie(引) js设置cookie有很多种方法. 第一种:(这个是w3c官网的代码) <script> //设置cookie function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toUTCString(); docum
function addCookie(objName,objValue,objHours){//添加cookie var str = objName + "=" + escape(objValue); if(objHours > 0){//为0时不设定过期时间,浏览器关闭时cookie自动消失 var date = new Date(); var ms = objHours*3600*1000; date.setTime(date.getTime() + ms); str +=