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     }

JS localStorage 存储变量,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。