简体   繁体   English

如何使字符串出现在本地存储的某个位置?

[英]How can I make a string appear in a certain location from localstorage?

I have the following code:我有以下代码:

<html>
  <button id = "customizations" button onclick = "loadsaved()" title = "Load">L</button>
  <div id = "text" contenteditable = "true"></div>
</html>

<script>
function loadsaved() {

 let stringValue = document.getElementById("text").innerHTML;
 let y = localStorage.getItem("savetext");

}
</script>

What I want is, when I press the button, it'll load the string that was saved in local storage in that div text box.我想要的是,当我按下按钮时,它将在该 div 文本框中加载保存在本地存储中的字符串。 How can I achieve this?我怎样才能做到这一点?

document.getElementById("text").innerHTML =localStorage.getItem("savetext");

You had the answer almost: here ia a little modification你几乎得到了答案:这里是一个小修改

function loadsaved() {

 document.getElementById("text").innerHTML = localStorage.getItem("savetext");

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM