标签:
HTML code:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="appWeb3.js"></script>
</head>
<body>
<table>
<tr><td>姓名:</td><td><input type="text" id="name"></td></tr>
<tr><td>email:</td><td><input type="text" id="email"></td></tr>
<tr><td>电话号码:</td><td><input type="text" id="tel"></td></tr>
<tr><td>备注:</td><td><input type="text" id="memo"></td></tr>
<tr>
<td></td>
<td><input type="button" value="保存" onclick="saveStorage()"></td>
</tr>
</table>
<hr>
<p>检索:
<input type="text" id="find">
<input type="button" value="检索" onclick="findStorage(‘msg‘)">
</p>
<p id="msg"></p>
</body>
</html>
JavaScript code:
/**
* Created by hp on 2015/8/30.
*/
function saveStorage(){
var data = new Object;
data.name = document.getElementById("name").value;
data.email = document.getElementById("email").value;
data.tel = document.getElementById("tel").value;
data.memo = document.getElementById("memo").value;
var str = JSON.stringify(data);
localStorage.setItem(data.name,str);
alert("数据已经保存");
}
function findStorage(id){
var find = document.getElementById(‘find‘).value; //获取值
var str = localStorage.getItem(find); //存储获得
var data = JSON.parse(str);
var result = "姓名:"+data.name +"<br>";
result += "姓名:"+data.email +"<br>";
result += "姓名:"+data.tel +"<br>";
result += "姓名:"+data.memo +"<br>";
var target = document.getElementById(id);
target.innerHTML = result;
}
标签:
原文地址:http://www.cnblogs.com/htmlphp/p/4771561.html