标签:
length 键值对个数
//结合length和key()实现迭代键值对
for(var i = 0, len = storage.length; i < len; i++){
key = storage.key(i);
value = storage.getItem(key);
...
}
数据也是Storage实例的属性,可以通过.[name]读写值
//for-in迭代键值对
for(var key in storage){
value = storage.getItem(key);
...
}
globalStorage["wrox.com"].name="jack";//wrox.com及其子域可访问
globalStorage["net"].name="jack";//任何.net结尾的域名可访问
globalStorage[""].name="jack";//任何域名可以访问
//通过location指定当前域
globalstorage[location。host].name="jack"
//兼容只支持globalStorage的浏览器
function getLcLocalStorage(){
if(typeof localStorage == "object"){
return localStorage;
}
else if(typeof globalStorage == "object"){
return globalStorage;
}
else{
throw new Error("Local storage not available")
}
}
var storage = getLocalStorage
标签:
原文地址:http://www.cnblogs.com/initial-wu/p/5341320.html