cookie的写入与读出

cookie在jquery中有指定的cookie操作类

$.cookie('the_cookie'); // 读取 cookie 
$.cookie('the_cookie', 'the_value'); // 存储 cookie 
$.cookie('the_cookie', 'the_value', { expires: 7 }); // 存储一个带7天期限的 cookie 
$.cookie('the_cookie', '', { expires: -1 }); // 删除 cookie

今天要读取cookie,发现提示$.cookie is not a function 

于是使用了下面的方法

document.cookie="name="+username;  

var arr,reg = new RegExp("(^| )name=([^;]*)(;|$)");
var aa= "";
if(arr=document.cookie.match(reg)){
  aa= unescape(arr[2]);
}
原文地址:https://www.cnblogs.com/baby123/p/5732909.html