<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>留言本</title>
<script src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function(){
//本地留言板内容不为空
if(localStorage.getItem("k_con")!=null){
"k_con",$("#dCon").html(localStorage.getItem("k_con"));
}
});
function PostClick(){
var trCon=$("#trCon").val();
//将获取的内容直接加到 给定的div中
$("#dCon").append("<div>"+trCon+"</div>");
//将留言板内容存入本地
localStorage.setItem("k_con",$("#dCon").html());
}
</script>
</head>
<body>
<div><textarea id="trCon" cols="30" rows="8"></textarea></div>
<div><input type="button" value="发表" onclick="PostClick();"> <input type="button" value="清除"> </div>
<div id="dCon"></div>
</body>
</html>