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

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. 尽可能保留原有数据,建立UEFI与BIOS双启PE优盘

    尽可能保留原有数据,建立UEFI与BIOS双启PE优盘1.确保优盘或者移动硬盘有一个FAT32分区,如果没有FAT32分区,就用傲梅分区助手或者ppm转换一个现有的分区到FAT32分区0x0C,或者新 ...

  2. laravel 加中间件的方法 防止直接打开后台

    路由 routes.php Route::group(['middleware' => ['web','admin.login.login']], function () { //后台首页路由 ...

  3. ASP.NET页面优化,提高载入速度[转]

      ASP.NET页面载入速度提高的一些做法: 1.采用 HTTP Module 控制页面的生命周期. 2.自定义Response.Filter得到输出流stream生成动态页面的静态内容(磁盘缓存) ...

  4. NGINX 定时器

    写在前面 写NGINX系列的随笔,一来总结学到的东西,二来记录下疑惑的地方,在接下来的学习过程中去解决疑惑. 也希望同样对NGINX感兴趣的朋友能够解答我的疑惑,或者共同探讨研究. 整个NGINX系列 ...

  5. CSS Hack大全-教你如何区分出IE6-IE10、FireFox、Chrome、Opera

    CSS Hack大全-教你如何区分出IE6-IE10.FireFox.Chrome.Opera 转载自:http://www.jb51.net/article/50116.htm 现在的浏览器IE6- ...

  6. 读javascript高级程序设计15-Ajax,CORS,JSONP,Img Ping

    平时用惯了jQuery.ajax之类的方法,却时常忽略了它背后的实现,本文是学习了AJAX基础及几种跨域解决方案之后的一些收获. 一.AJAX——XMLHttpRequest 谈起Ajax我们都很熟悉 ...

  7. 【jQuery】serializeArray()与serialize()的区别

    serialize()序列化表单元素为字符串,用于 Ajax 请求. serializeArray()序列化表单元素为JSON数据. 具体实例如下: 1 <!DOCTYPE html PUBLI ...

  8. HDU 4940 Destroy Transportation system(2014 Multi-University Training Contest 7)

    思路:无源汇有上下界可行流判定, 原来每条边转化成  下界为D  上界为 D+B   ,判断是否存在可行流即可. 为什么呢?  如果存在可行流  那么说明对于任意的 S 集合流出的肯定等于 流入的, ...

  9. android快速入门

    1.安装环境(jre  java 运行环境,jdk java 开发工具包) 2.android studio 一.快捷键的使用 1. To open any class in the editor q ...

  10. The 10 best sweet treats in Singapore

    Every time I walk out of Changi airport's air-conditioning into the humid outdoors, there's a sweet ...