我正在制作一个文件,您可以在其中键入" post"它显示了它。我怎样才能做到#34;发布"保存所以下次我在Chrome上打开文件时它仍会显示变量文本吗?
<h3 style="color:teal;padding:8">My Post</h3>
<p id="post" style="padding:8"></p>
<button id="myButton" onclick="var post=prompt('What would you like to say?');document.getElementById('post').innerHTML = post;">Edit!</button>
&#13;
答案 0 :(得分:0)
这项工作就像你想要它一样
<h3 style="color:teal;padding:8">My Post</h3>
<p id="post" style="padding:8"></p>
<button id="myButton" onclick="var post=prompt('What would you like to say?');document.getElementById('post').innerHTML = post;localStorage.setItem("post", post);">Edit!</button>
<script>
document.getElementById('post').innerHTML = localStorage.getItem("post");
</script>