新手求前辈指导OTZ
这是html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>简单的网页留言板</title>
<script type="text/javascript" src="canvas29.js"></script>
</head>
<body>
<h1>简单的网页留言板</h1>
<textarea id="dome" cols="50" rows="10"></textarea>
<br/>
<input type="button" value="保存" onclick="saveStorage('dome')">
<input type="button" value="清空" onclick="clearStorage('msg')">
<input type="button" value="读取" onclick="loadStorage('msg')">
<hr>
<p id="msg"></p>
</body>
</html>
这是js:
function saveStorage(id){
var data=document.getElementById("dome").value;
var time=new Date().getTime();
localStorage.setItem(time,data);
alert("数据已保存!");
loadStorage('msg');
}
function loadStorage(id){
var result='<table border="1">';
for(var i=0;i<localStorage.length;i++){
var value=localStorage.getItem(localStorage.key(i));
var date=new Date();
date.setTime(localStorage.key(i));
var datestr=date.toGMTString();
result +='<tr><td>'+'第'+(i+1)+'条数据</td><td>'+value+'</td><td>'+datestr+'</td></tr>';
}
result +='</table>';
var target=document.getElementById(id); —————— 就是这个地方的id,为什么不是"dome"?
target.innerHTML=result;
}
function clearStorage(id){
localStorage.clear();
alert("数据已成功删除!");
loadStorage('msg');
}
陌上人如玉_010
慕的地6079101
相关分类