【发布时间】:2018-01-03 19:24:38
【问题描述】:
我已经使用这些代码制作了一个简单的笔记应用程序。它必须通过按记住按钮将文本框值存储到 localStorage 中。然后显示它,但按另一个按钮。但它不起作用。
<HTML>
<head>
<script>
function myfunction1() { //remember code var
texttosave = document.getElementById('textline').innerHTML;
localStorage.setItem('mynumber', texttosave);
}
function
myfunction2() { //recall code
document.getElementById('recalledtext').innerHTML =
localStorage.getItem('mynumber');
}
</script>
</head>
<body>
<input type="text" id="textline" />
<button id="rememberer" onclick='myfunction1()'>remember text</button>
<button id="recaller" onclick='myfunction2()'>recall text </button>
<p id="recalledtext">Loading</p>
</body>
</HTML>
【问题讨论】:
-
你的控制台有错误吗?
-
有同样的问题。但他们的答案对我不起作用。
-
@sheplu 我是网络脚本的新手。你在说什么控制台?
-
我刚刚将代码发布到“test.html”文件中并通过localhost打开。
-
我还需要做其他事情吗?
标签: javascript html stack-overflow angular2-localstorage