首页 > 代码库 > 利用html5的localStorage做一个备忘录
利用html5的localStorage做一个备忘录
1 function saveStorage(id){ 2 var data =http://www.mamicode.com/ 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 =http://www.mamicode.com/ 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 =http://www.mamicode.com/ 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 =http://www.mamicode.com/ 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 =http://www.mamicode.com/ 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 =http://www.mamicode.com/ 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 }
利用html5的localStorage做一个备忘录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。