<html lang="en">
<head>
<meta charset="UTF-8">
<title>练习 网站导航</title>
<style>
*{
margin:0;
padding:0;
list-style:none;}
</style>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<div style="border: 2px dashed #ccc;width:320px;text-align:center;">
<label for="keyname">别名(key):</label>
<input type="text" id="keyname" name="keyname" class="text"/>
<br/>
<label for="sitename">网站名:</label>
<input type="text" id="sitename" name="sitename" class="text"/>
<br/>
<label for="siteurl">网 址:</label>
<input type="text" id="siteurl" name="siteurl"/>
<br/>
<input type="button" οnclick="save()" value="新增记录"/>
<hr/>
<label for="search_site">输入别名(key):</label>
<input type="text" id="search_site" name="search_site"/>
<input type="button" οnclick="find()" value="查找网站"/>
<p id="find_result"><br/></p>
</div>
<script>
function save(){
var site=new Object;
site.keyname=$("#keyname").val();
site.sitename=$("#sitename").val();
site.siteurl=$("#siteurl").val();
var str=JSON.stringify(site);
localStorage.setItem(site.keyname,str);
console.log(localStorage.getItem(site.keyname));
}
function find(){
var search_site=$("#search_site").val();
var str=localStorage.getItem(search_site);
var site = JSON.parse(str);
$("#find_result").get(0).innerHTML=site.sitename;
}
</script>
</body>
</html>