标签:style blog io os ar 使用 java sp strong
webstorage 分sessionStorage和localstorage,sessionStorage是临时保存,localStorage是永久保存。 sessionStorage如果浏览器关闭了,数据就没有了,而localStorage则不会。
示例
<span style="font-family:Microsoft YaHei;font-size:18px;"><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script language="JavaScript"> function saveStorage(id){ var target = document.getElementById(id); var str = target.value; sessionStorage.setItem("msg", str); } function loadStorage(id){ var target = document.getElementById(id); var msg = sessionStorage.getItem("msg"); target.innerHTML = msg; } </script> </head> <body> <p id="msg"></p> <input type="text" id="input"/> <button onclick="saveStorage('input')">保存数据</button> <button onclick="loadStorage('msg')">获取数据</button> </body> </html></span>
标签:style blog io os ar 使用 java sp strong
原文地址:http://blog.csdn.net/wangxw8746/article/details/40506947