标签:
localStorage 和sessionStorage
localStorage.setItem("b","isaac");//设置b为"isaac"
var b = localStorage.getItem("b");//获取b的值
localStorage.removeItem("c");//清除c的值
localStorage.clear() //清空
sessionStorage的用法是一样的。
对于不知道键去取值的情况,
var storage = window.localStorage;
function showStorage(){
for(var i=0;i<storage.length;i++){
//key(i)获得相应的键,再用getItem()方法获得对应的值
document.write(storage.key(i)+ " : " + storage.getItem(storage.key(i)) + "<br>");
}
}
标签:
原文地址:http://www.cnblogs.com/joesbell/p/5909917.html