简体   繁体   中英

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. 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");

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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