首页 > web前端 > js教程 > 正文

改版了网上的一个js操作userdata_javascript技巧

php中文网
发布: 2016-05-16 19:14:12
原创
1300人浏览过

复制代码 代码如下:


下面是其它网友文章:
js 保存大量数据.
IE系列存储到电脑上,直到删除文件.
FF关闭则删除
复制代码 代码如下:

<script> <BR>//userData类 <BR>var RuserData={ <BR>o:null, <BR>timeExpires:7, <BR>browser:'', <BR>//初始化userdata <BR>init:function() <BR>{ <BR>if(this.browser != '') <BR>return true; <BR>if(window.ActiveXObject)//for IE { <BR>try{ <BR>this.o=document.createElement("input"); <BR>this.o.id="Ruserdata"; <BR>this.o.type="hidden"; <BR>this.o.style.behavior="url(#default#userData)"; <BR>this.browser='ie'; <BR>document.body.appendChild(this.o); <BR>return true; <BR>}catch(e){return false;} <BR>}else if(window.sessionStorage)//FF 2.0+*/ <BR>{ <BR>try{ <BR>this.o=window.sessionStorage; <BR>this.browser='ff'; <BR>return true; <BR>}catch(e){return false;} <BR>} <BR>return false; <BR>}, <BR>setVal:function(key,val,timeout/*正定义超时时间,为空用默认值*/){ <BR>this.init(); <BR>if(this.browser == 'ie'){ <BR>try{ <BR>this.o.load(key); <BR>this.o.expires=typeof timeout == 'undefined' ? this.getTimeLimit(this.timeExpires) : this.getTimeLimit(timeout); <BR>this.o.setAttribute('value',val); <BR>this.o.save(key); <BR>return true; <BR>}catch(e){return false} <BR>}else if(this.browser == 'ff'){ <BR>try{this.o.setItem(key,val);return true;} <BR>catch(e){return false} <BR>} <BR>}, <BR>getVal:function(key){ <BR>this.init(); <BR>if(this.browser == 'ie'){ <BR>try{ <BR>this.o.load(key); <BR>return this.o.getAttribute('value'); <BR>}catch(e){return false;} <BR>}else if(this.browser == 'ff'){ <BR>try{return this.o.getItem(key);} <BR>catch(e){return false} <BR>} <BR>}, <BR>delVal:function(key){ <BR>this.init(); <BR>if(this.browser == 'ie'){ <BR>try{ <BR>this.o.load(key); <BR>this.o.expires=new Date(315532799000).toUTCString(); <BR>this.o.save(key); <BR>return true; <BR>} <BR>catch(e){return false;} <BR>}else if(this.browser == 'ff'){ <BR>try{this.o.removeItem(key);return true;} <BR>catch(e){return false} <BR>} <BR>}, <BR>getTimeLimit:function(days/*设置超时天数*/){ <BR>var d=new Date(); <BR>d.setDate(d.getDate() + days); <BR>return d.toUTCString(); <BR>} <BR>}; <BR>window.onload=function(){ <BR>//alert(RuserData.delVal('renchao')); <BR>//alert(RuserData.setVal('renchao','本站www.jb51.net')); <BR>alert(RuserData.getVal('renchao')); <BR>} <BR></script>

使用方法:
复制代码 代码如下:

window.onload=function(){
//alert(RuserData.delVal('renchao'));
//alert(RuserData.setVal('renchao','本站www.jb51.net'));
alert(RuserData.getVal('renchao'));
}
java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号