javascript - 跨浏览器 localStorage

  显示原文与译文双语对照的内容
94 0

我想象一个在to中编写的待办事项列表,而不使用框架来查看 vmkernel 跨浏览器 兼容性。

脚本是


function addText(){
var input = document.getElementById('input').value;
date = new Date();
var time = date.getTime();
if (input!=="") {
 localStorage.setItem(time,"lalala");
 document.getElementById('input').value = '';
}};

function loadText(){
if (window.localStorage) {
 for(var i in window.localStorage){
 console.log(i+"--------theiiiiiii");
 var z = localStorage.getItem(i);
 console.log(z+"--------you keep me satisfied");
 }
} else {
 alert("Your Browser does not support LocalStorage.");
}
}

现在,在 Chrome 中,几乎在 Firefox 中,我得到了设置值加上所有localStorage操作符。 谁知道这个问题的解决方法?


1381311087810--------theiiiiiii
lalala--------you keep me satisfied
length--------theiiiiiii
null--------you keep me satisfied
key--------theiiiiiii
null--------you keep me satisfied
getItem--------theiiiiiii
null--------you keep me satisfied
setItem--------theiiiiiii
null--------you keep me satisfied
removeItem--------theiiiiiii
null--------you keep me satisfied
clear--------theiiiiiii
null--------you keep me satisfied

时间: 原作者:

108 4

尝试仅列出密钥:


function loadText(){
 if (window.localStorage) {

///list all keys from object
 var keys = Object.keys(localStorage);

 for(var i, key; key = keys[i]; i++) {
 console.log(key +"--------theiiiiiii");
 var z = localStorage.getItem(key);
 console.log(z +"--------you keep me satisfied");
 }
 } else {
 alert("Your Browser does not support LocalStorage.");
 }
}

原作者:
...