<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>H5表格提交</title> <script src="appWeb.js"></script></head><body> <p id="msg"></p> <textarea id="memo" cols="60" rows="10"></textarea><br/> <input type="button" value="追加数据" onclick="saveStorage('memo')"> <input type="button" value="删除数据" onclick="clearStorage()"></body></html>
function saveStorage(id){ var data = document.getElementById(id).value; var time = new Date().getTime(); localStorage.setItem(time,data); loadStorage('msg'); }function loadStorage(id){ var result = "<table border = '1'>"; for(var i = 0;i < loadStorage.length;i++){ var key = localStorage.key(i); var value = localStorage.getItem(key); var date = new Date(); date.setTime(key); result += "<tr><td>"+value+"</td><td>"+date+"</td></tr>"; } result += "</table>"; var target = document.getElementById(id); target.innerHTML = result; }function clearStorage(){ localStorage.clear(); loadStorage('msg'); }
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>H5表格提交</title> <script src="appWeb.js"></script></head><body> <p id="msg"></p> <textarea id="memo" cols="60" rows="10"></textarea><br/> <input type="button" value="追加数据" onclick="saveStorage('memo')"> <input type="button" value="删除数据" onclick="clearStorage()"></body></html>
function saveStorage(id){ var data = document.getElementById(id).value; var time = new Date().getTime(); localStorage.setItem(time,data); loadStorage('msg'); }function loadStorage(id){ var result = "<table border = '1'>"; for(var i = 0;i < loadStorage.length;i++){ var key = localStorage.key(i); var value = localStorage.getItem(key); var date = new Date(); date.setTime(key); result += "<tr><td>"+value+"</td><td>"+date+"</td></tr>"; } result += "</table>"; var target = document.getElementById(id); target.innerHTML = result; }function clearStorage(){ localStorage.clear(); loadStorage('msg'); }
上記は、Html5 学習の旅 - html5 メッセージ メモ帳の開発 (17) の内容です。その他の関連コンテンツについては、PHP 中国語 Web サイト (www.php.cn) に注目してください。