<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<input type="text" id="demo" />
<p id="text"></p>
<button type="button" onClick="savestorage()" value="">保存数据</button>
<button type="button" onClick="loadstorage()" value="">读取数据</button>
<script>
function savestorage()
{
var textValue=document.getElementById("demo").value;
localStorage.setItem("message",textValue);
}
function loadstorage()
{
var tar=document.getElementById("text");
var msg=localStorage.getItem("message");/*注意此处是getItem*/
tar.innerHTML=msg;
}
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<input type="text" id="demo" />
<p id="text"></p>
<button type="button" onClick="savestorage()" value="">保存数据</button>
<button type="button" onClick="loadstorage()" value="">读取数据</button>
<script>
function savestorage()
{
var textValue=document.getElementById("demo").value;
localStorage.setItem("message",textValue);
}
function loadstorage()
{
var tar=document.getElementById("text");
var msg=localStorage.getItem("message");/*注意此处是getItem*/
tar.innerHTML=msg;
}
</script>
</body>
</html>