1 function saveStorage(id){ 2 var data = document.getElementById(id).value; 3 var timeNow = new Date(); 4 localStorage.setItem(timeNow,data); 5 localStorage.setItem(timeNow+1,timeNow); 6 loadStorage(‘msg‘); 7 } 8 function loadStorage(id){ 9 var result = ‘<table border = "1">‘; 10 for(var i=0,j=1;i<localStorage.length;i+=2,j++) 11 { 12 var key = localStorage.key(i); 13 var value = localStorage.getItem(key); 14 result += ‘<tr><td>‘+j+‘</td><td>‘+value+‘</td><td>‘+localStorage.getItem(key+1)+‘</td></tr>‘; 15 } 16 result += ‘</table>‘; 17 var target = document.getElementById(id); 18 target.innerHTML = result; 19 } 20 function clearStorage(id){ 21 localStorage.clear(); 22 alert("date deleted"); 23 }
1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title>simple note</title> 6 <script type="text/javascript"src="comment.js"></script> 7 </head> 8 <body> 9 <h1>add note</h1> 10 <textarea id="dome" cols="60" rows="2"></textarea><br/><!--文本输入区域--> 11 <input type="button" value="save" onclick="saveStorage(‘dome‘);"> 12 <input type="button" value="load" onclick="loadStorage(‘msg‘);"> 13 <input type="button" value="clear" onclick="clearStorage(‘msg‘);"> 14 <h1>note</h1> 15 <hr> 16 <p id="msg"></p><!--历史输入区域--> 17 </body> 18 </html>
aa
1 f
function saveStorage(id){ var data = document.getElementById(id).value; var timeNow = new Date(); localStorage.setItem(timeNow,data); localStorage.setItem(timeNow+1,timeNow); loadStorage(‘msg‘); } function loadStorage(id){ var result = ‘<table border = "1">‘; for(var i=0,j=1;i<localStorage.length;i+=2,j++) { var key = localStorage.key(i); var value = localStorage.getItem(key); result += ‘<tr><td>‘+j+‘</td><td>‘+value+‘</td><td>‘+localStorage.getItem(key+1)+‘</td></tr>‘; } result += ‘</table>‘; var target = document.getElementById(id); target.innerHTML = result; } function clearStorage(id){ localStorage.clear(); alert("date deleted"); }
unction saveStorage(id){ 2 var data = document.getElementById(id).value; 3 var timeNow = new Date(); 4 localStorage.setItem(timeNow,data); 5 localStorage.setItem(timeNow+1,timeNow); 6 loadStorage(‘msg‘); 7 } 8 function loadStorage(id){ 9 var result = ‘<table border = "1">‘; 10 for(var i=0,j=1;i<localStorage.length;i+=2,j++) 11 { 12 var key = localStorage.key(i); 13 var value = localStorage.getItem(key); 14 result += ‘<tr><td>‘+j+‘</td><td>‘+value+‘</td><td>‘+localStorage.getItem(key+1)+‘</td></tr>‘; 15 } 16 result += ‘</table>‘; 17 var target = document.getElementById(id); 18 target.innerHTML = result; 19 } 20 function clearStorage(id){ 21 localStorage.clear(); 22 alert("date deleted"); 23 }
时间: 2024-10-28 11:52:23