<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title></title>
<script src="js/appweb.js"></script>
</head>
<body>
<p id="msg"></p>
<input type="text" id="input">
<input type="button" value="保存数据" onclick="saveStorage(‘input‘)">
<input type="button" value="读取数据" onclick="loadStorage(‘msg‘)">
</body>
</html>
js:
appweb.js
//function saveStorage(id){
// var target = document.getElementById(id);
// var str = target.value;
// //保存数据的方法 key value
// sessionStorage.setItem("message",str);
//}
//
//function loadStorage(id){
// var target = document.getElementById(id);
// //读取数据
// var msg = sessionStorage.getItem("message");
// target.innerHTML = msg;
//}
//值储存了网页没关的信息,网页一关就消失了
function saveStorage(id){
var target = document.getElementById(id);
var str = target.value;
localStorage.setItem("message",str);
}
function loadStorage(id){
var target = document.getElementById(id);
var msg = localStorage.getItem("message");
target.innerHTML = msg;
}