Home > php教程 > php手册 > javascript原生Html5本地存储之jsStorage.js

javascript原生Html5本地存储之jsStorage.js

WBOY
Release: 2016-06-07 11:36:48
Original
1500 people have browsed it

jsStorage.js实现对html5的localstorage和sessionStorage的封装操作;
详情请阅读: https://git.oschina.net/wuquanyao/JsStorage
/*+==============================================<br>   + 我不只是一个程序员,我更希望用此创造价值<br>   + author:wuquanyao<br>   + email:wqynqa@163.com<br>   * version:1.0.0 <br>   +==============================================*/<br> var storage=(function(){<br>     var Storage = function(type){<br>         this.storage = null;<br>         if(typeof('type') === 'undefined' || type === 'local')<br>             this.storage = window.localStorage;<br>         else if(type === 'session')<br>             this.storage = window.sessionStorage;<br>     }<br>     Storage.prototype.set=function(key, value){<br>         this.storage.setItem(key, escape(value));<br>     }<br>     Storage.prototype.get=function(key){<br>         return unescape(this.storage.getItem(key));<br>     }<br>     Storage.prototype.remove=function(key){<br>         this.storage.removeItem(key);<br>     }<br>     Storage.prototype.clear=function(){<br>         this.storage.clear();<br>     }<br>     Storage.prototype.key=function(index){<br>         return this.storage.key(index);<br>     }<br>     Storage.prototype.hasKey=function(key)<br>     {<br>         for(var i in this.storage){<br>             if(i === key){<br>                 return true;<br>             }<br>         }<br>         return false;<br>     }<br>     Storage.prototype.hasVal=function(value)<br>     {<br>         for(var i in this.storage){<br>             if(unescape(this.storage[i]) === value){<br>                 return true;<br>             }<br>         }<br>         return false;<br>     }<br>     Storage.stringify = function(data){<br>         return JSON.stringify(data);<br>     }<br>     Storage.parse = function(data){<br>         return JSON.parse(data);<br>     }<br>     Storage.support = function(){<br>         if(window.localStorage && window.sessionStorage) return true;<br>         return false;<br>     }<br>    return Storage;<br> })(window);

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template