制作过程我就不说了,程序下面会占出来

define(function(){
if('localStorage' in window) return;
function Storage(){
this.box = document.body || document.getElementByTagName('head')[0] || document.documentElement;
this.name = 'localStorage'
this.data = document.createElement(this.name);
this.data.addBehavior("#default#userData");
this.box.appendChild(this.data);
this.map = [];
this.length = this.length();
}
Storage.prototype.setItem = function(name,val){
if(name=='localStorage-map'){
throw new Error("this is localStorage in key [localStorage-map] not use!")
return ;
}
if(this.map.length==0){
this.data.load('localStorage-map');
var data = this.data.getAttribute('localStorage-map');
if(data!=null){
this.map = data.split(',');
}
}
var flag = true;
for(var i in this.map){
if(this.map[i] == name){
flag = false;
}
}
if(flag){
this.map.push(name)
}
this.data.setAttribute(name,val);
var date = new Date();
date.setDate(date.getDate()+700);
this.data.expires = date.toUTCString();
this.data.save(name);
this.data.setAttribute('localStorage-map',this.map);
this.data.save('localStorage-map');
}
Storage.prototype.getItem = function(name){
if(name == 'localStorage-map'){
throw new Error("this is localStorage in key [localStorage-map] not use!");
return;
}
this.data.load(name);
return this.data.getAttribute(name);
};
Storage.prototype.length = function(){
if(this.map.length==0){
this.data.load('localStorage-map');
var data = this.data.getAttribute('localStorage-map');
if(data!=null){
this.map = data.split(',');
}
}
for (var i = this.map.length - 1; i >= 0; i--) {
alert(this.getItem(this.map[i]))
if(this.getItem(this.map[i])==undefined || this.getItem(this.map[i])==""){
this.map.splice(i,1);
}
}
return this.map.length;
};
Storage.prototype.removeItem = function(name){
if(typeof name=="undefined" || name=="") return;
if(this.map.length==0){
if(this.getItem('localStorage-map')!=null){
this.map = this.getItem('localStorage-map').split(',');
}
}
for(var i in this.map){
if(this.map[i] == name){
this.map.splice(i,1);
}
}
this.data.load(name);
this.data.setAttribute(name,undefined);
this.data.save(name);
return true;
},
Storage.prototype.clear=function(){
if(this.map.length==0){
if(this.getItem('localStorage-map')!=null){
this.map = this.getItem('localStorage-map').split(',');
}
}
for(var i in this.map){
this.removeItem(this.map[i]);
}
}
window.localStorage = new Storage();
});

调用程序

localStorage.setItem('value','{askdjf:ddd}')
localStorage.setItem('name','{ddddddd:ddd}')
alert(localStorage.getItem('value'))
alert(localStorage.getItem('name'))
alert(localStorage.removeItem('name'))
alert(localStorage.length);

我只是简单测试了一下可以,不知道哪里还有问题,望指点一二!!!!!

localStorage兼容ie6/7 用addBehavior 实现的更多相关文章

  1. localStorage兼容方案

    localStorage是H5的存储方案,各大浏览器支持都相当不错,唯一悲催的就是IE,这个浏览器界的另类总是显得格格不入. IE “Internet选项”->“安全”中有一个“启动保护模式”的 ...

  2. JavaScript简单分页,兼容IE6,~3KB

    简介 兼容IE6+及现代浏览器的简单分页,支持同一页面多个分页. 使用 Browser <link rel="stylesheet" href="css/GB-pa ...

  3. html5 图片上传,支持图片预览、压缩、及进度显示,兼容IE6+及标准浏览器

    以前写过上传组件,见 打造 html5 文件上传组件,实现进度显示及拖拽上传,兼容IE6+及其它标准浏览器,对付一般的上传没有问题,不过如果是上传图片,且需要预览的话,就力有不逮了,趁着闲暇时间,给上 ...

  4. JQuery兼容IE6问题汇总(不断更新)

    兼容IE6真是苦逼的差事,无奈中... 逗号的问题:IE6中要去掉最后的逗号 var o={ id:1, Name:"abc", //这里的逗号一定要去掉 } HTML的结构,由于 ...

  5. .使用 HTML+CSS 实现如图布局,border-widht 5px,一个格子大小是 50*50,hover时候边框变为红色(兼容IE6+,考虑语义化的结构)

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  6. 表单美化-原生javascript和jQuery多选按钮(兼容IE6)

    前些天我们讲了下单选按钮的美化今天来做表单元素多选按钮的美化.我们的想法是:利用多选按钮是否被选中和是否不给选择的特性来为按钮的父元素添加对应的样式,就是说用什么的样式是由按钮的状态来决定. 用到的图 ...

  7. min-height最小高度的实现(兼容IE6、IE7、FF)(解决IE6不兼容min-height)

    <!doctype html><html> <head> <meta charset="UTF-8"> <meta name= ...

  8. 一款兼容IE6并带有多图横向滚动的jquery特效

    一款兼容IE6并带有多图横向滚动的jquery特效,自动切换多个图片的jquery特效效果, 为大家分享这个的原因是,这款特效在兼容IE6上面很完美,实用性就广很多了. 适用浏览器:IE6.IE7.I ...

  9. jQuery编写的一款兼容IE6的图片轮播幻灯片

    jQuery编写的一款兼容IE6的图片轮播幻灯片,很不错的一款jquery特效.大家可以下载下来研究研究. 每隔几秒就自动切换一波图片,此效果兼容性还做的不错,适合居多的浏览器. 适用浏览器:IE6. ...

随机推荐

  1. PetShop的系统架构设计

    <解剖PetShop>系列 一.PetShop的系统架构设计 http://www.cnblogs.com/wayfarer/archive/2007/03/23/375382.html ...

  2. 003_kafka_主要配置

    1.broker配置 2.Producer主要配置 3.Consumer主要配置 出错提示信息: replication factor: 1 larger than available brokers ...

  3. EaseType缓动函数

    http://sol.gfxile.net/interpolation/   一篇很详细的图文

  4. string.Format格式化

    ,)//填充,结果为02,003

  5. what is archeage honor weapons?

    in my opinion,there are many kinds of weapons in archeage online, those include basic weapons and ma ...

  6. nginx https使用

    默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中.通常这 ...

  7. sprite图在移动端的使用

    做移动端页面时,设计稿中的切片图片往往是实际的2倍,此处记录图片正常显示大小的技巧. 当图片是单张的话,可以对容器设计实际大小,然后设置background-image,为了让图片缩小一倍,可以设置b ...

  8. blocked file type by sharepoint 分类: Sharepoint 2015-07-05 07:45 6人阅读 评论(0) 收藏

    o add or remove blocked file types by using Central Administration Verify that you have the followin ...

  9. tomcat简单文服

    1.修改tomcat配置文件 web.xml 将listings的value值改为true. DefaultServlet在Tomcat中主要是做目录列表(Directory Listing)用. 2 ...

  10. MQTT实现长连接,IM最简单实例

    1,引入MqttSDK. 2, 头文件 #import "MQTTSession.h" //定义主题#define kTopic @"lichanghong"/ ...