如何保存文件提示的变量答案,以便保存?

时间:2017-11-02 04:15:13

标签: javascript html variables

我正在制作一个文件,您可以在其中键入" 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;
&#13;
&#13;

1 个答案:

答案 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>