//获取cookie cname代表你的key比如存储的code就使用code获取值 function GetCookie(cname) { var name = cname + "="; var c = document.cookie.split(";"); for (var i = 0; i < c.length; i++) { var ca = c[i].trim(); //判断是否存在 if (ca.indexOf(name) == 0) { //正确截取Cookie值 return ca.substring(name.length, ca.length); } } return ""; }