【发布时间】:2016-04-05 10:00:41
【问题描述】:
我仍然尝试为便笺制作本地存储。我想在打开粘性之前自动查看(打开)所有页面,当页面刷新这么长时间,直到它们被 ESC 关闭。通过ESC工作关闭,但本地存储无法保存粘性...
https://jsfiddle.net/venntr/14fs0fef/3/
if (localStorage["note"])
{
var user = localStorage["note"] ;
document.getElementById("note").value = user ;
}
else
{
document.getElementById("note").placeholder = "notes" ;
console.log("notes not found in localStorage")
}
document.getElementById("save").addEventListener("click", function ()
{
var user = document.getElementById("note").value ;
localStorage.setItem("note", note) ;
alert("note id saved") ;
} , false);
function closeIt(that) {
var cls = parseInt(that.parent().parent().attr('class').split(' ')[1]);
var index = arr.indexOf(cls);
console.log('.note.'+cls+' '+index);
arr.splice(index,1);
that.parent().parent().remove();
}
【问题讨论】:
-
document.getElementById("note").placeholder = "notes" ;这是一个语法错误。 -
你正在将用户作为变量但设置注释
var user = document.getElementById("note").value ; localStorage.setItem("note", note) ; -
检查这一行 localStorage.setItem("note", note) ;我认为你需要把用户放在 note.like 这个 localStorage.setItem("note", user) ;
-
Ech.. 还是不行:( jsfiddle.net/venntr/14fs0fef/12
标签: javascript jquery local-storage