HTML5本地存储

在HTML5以前页面刷新以后页面的数据就会被从新加载。在服务器端访问时咱们能够存储cookie来存储一些简单的数据。
html

设置cookie 此部分详见 http://www.w3school.com.cn/js/js_cookies.asp
bash

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>设置cookie</title>
</head>

<body>
<script>
    function setCookie(c_name,value,expiredays)//cookie名字,值,过时时间间隔
    {
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+ //能够使用 unescape() 对 escape() 编码的字符串进行解码。
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
    }
    
    setCookie("wang","ba",10);
    
</script>
</body>
</html>

在HTML5中拥有了比cookie更强大的sessionStorage、localStorage
服务器

cookie是放在document下的
cookie

而这二者是放在window下的
session

以localstorage为例
dom

一、设置函数

相关文章
相关标签/搜索