HTML5的存储

1.客户端存储的两种方式

localStoryage:没有时间限制的。

sessionStoryage:针对一个session的数据存储。(浏览器关闭掉之后就会销毁)

 

2.localStoryage

原理:当使用localStoryage存储的时候,会存储在浏览器(这里以谷歌浏览器为例)的Resource下(新版的谷歌浏览器是在Application下)的localStoryage中。

实例:

<body >    
        <textarea id="textarea" style="width: 200px;height: 200px;border: 1px solid black;"></textarea>
        <button id="button">保存</button>
<script>
    var textarea = document.getElementById('textarea');
//之后打开会进行读取
if(localStorage.text){ textarea.value = localStorage.text; } var button = document.getElementById('button'); button.onclick = function(){
//点击后进行保存 localStorage.text
= textarea.value; } </script> </body>

 

3.seesionStoryage

原理:当使用seesionStoryage存储的时候,会存储在浏览器(这里以谷歌浏览器为例)的Resource下(新版的谷歌浏览器是在Application下)的sessionStoryage中。

实例:

<body >    
        <textarea id="textarea" style="width: 200px;height: 200px;border: 1px solid black;"></textarea>
        <button id="button">保存</button>
<script src="js/easeljs.min.js"></script>
<script>
    var textarea = document.getElementById('textarea');
    if(sessionStorage.text){
        textarea.value = sessionStorage.text;
    }
    
    var button = document.getElementById('button');
    button.onclick = function(){
        sessionStorage.text = textarea.value;
    }
</script>
    </body>

 

转载于:https://www.cnblogs.com/comefuture/p/7600769.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值