<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>H5表格提交</title> <script src="appWeb.js"></script></head><body> <p id="msg"></p> <input type="text" id="input"> <input type="button" value="保存数据" onclick="saveStorage('input')"> <input type="button" value="读取数据" onclick="loadStorage('msg')"></body></html>
/** * Created by joy liu on 2015/9/22. */function saveStorage(id){ var target = document.getElementById(id); var string = target.value; sessionStorage.setItem("message",string); } function loadStorage(id){ var target = document.getElementById(id); var msg = sessionStorage.getItem("message"); target.innerHTML = msg; }
/** * Created by joy liu on 2015/9/22. *///function saveStorage(id){// var target = document.getElementById(id);// var string = target.value;// sessionStorage.setItem("message",string);//}//function loadStorage(id){// var target = document.getElementById(id);// var msg = sessionStorage.getItem("message");// target.innerHTML = msg;//}function saveStorage(id){ var target = document.getElementById(id); var string = target.value; localStorage.setItem("message",string); } function loadStorage(id){ var target = document.getElementById(id); var msg = localStorage.getItem("message"); target.innerHTML = msg; }
storage,之前可以在用戶端Cookies存貯用戶名等信息,後來發現Cookies存儲存在以下問題:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>H5表格提交</title> <script src="appWeb.js"></script></head><body> <p id="msg"></p> <input type="text" id="input"> <input type="button" value="保存数据" onclick="saveStorage('input')"> <input type="button" value="读取数据" onclick="loadStorage('msg')"></body></html>
/** * Created by joy liu on 2015/9/22. */function saveStorage(id){ var target = document.getElementById(id); var string = target.value; sessionStorage.setItem("message",string); } function loadStorage(id){ var target = document.getElementById(id); var msg = sessionStorage.getItem("message"); target.innerHTML = msg; }
local storage的實例
/** * Created by joy liu on 2015/9/22. *///function saveStorage(id){// var target = document.getElementById(id);// var string = target.value;// sessionStorage.setItem("message",string);//}//function loadStorage(id){// var target = document.getElementById(id);// var msg = sessionStorage.getItem("message");// target.innerHTML = msg;//}function saveStorage(id){ var target = document.getElementById(id); var string = target.value; localStorage.setItem("message",string); } function loadStorage(id){ var target = document.getElementById(id); var msg = localStorage.getItem("message"); target.innerHTML = msg; }
ml的內容為「3t」多相關內容請關注PHP中文網(m.sbmmt.com)!