cookie预:

什么是cookie?
cookie 是存储于访问者的计算机中的变量。每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie。你可以使用 JavaScript 来创建和取回 cookie 的值。
 localStorage.name='bob'             //localStorage的使用方法
document.cookie='name=bob;expires=Mon,31 Oct 2016 08:31:36 GMT'          //cookie的用法 
                            //      设定过期时间
 cookie 和 localStorage 不同的地方:
 1.保存数据的容量不同
2.cookie会随着浏览器的请求一起发送给服务器,而localStorage不会
3.使用方式上的不同
4.cookie有过期时间(当浏览器绘画结束后)  localstorage没有过期时间
 
//存储cookie
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
 //读取cookie
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""

}
转载自:http://www.cnblogs.com/luozhijian0120/p/6036067.html
原文地址:https://www.cnblogs.com/beyrl-blog/p/6040954.html