JS localStorage 存储变量

 1 if(!window.localStorage && /MSIE/.test(navigator.userAgent)){ 
 2         if(!window.UserData) { 
 3             window.UserData = function(file_name) { 
 4                 if(!file_name) file_name="user_data_default"; 
 5                 var dom = document.createElement('input'); 
 6                 dom.type = "hidden"; 
 7                 dom.addBehavior ("#default#userData"); 
 8                 document.body.appendChild(dom); 
 9                 dom.save(file_name); 
10                 this.file_name = file_name; 
11                 this.dom = dom; 
12                 return this; 
13             };
14     
15             window.UserData.prototype = { 
16                 setItem:function(k, v) { 
17                     this.dom.setAttribute(k,v); 
18                     this.dom.save(this.file_name); 
19                 }, 
20                 getItem:function(k){ 
21                     this.dom.load(this.file_name); 
22                     return this.dom.getAttribute(k); 
23                 }, 
24                 removeItem:function(k){ 
25                     this.dom.removeAttribute(k); 
26                     this.dom.save(this.file_name); 
27                 },
28                 clear:function() { 
29                    this.dom.load(this.file_name); 
30                    var now = new Date(); 
31                    now = new Date(now.getTime()-1); 
32                    this.dom.expires = now.toUTCString(); 
33                    this.dom.save(this.file_name); 
34                 }
35             }; 
36         } 
37         window.localStorage= new window.UserData("local_storage"); 
38     }

 

转载于:https://www.cnblogs.com/fengys-moving/p/3579827.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值