localstorage2
将文本框的内容在关闭刷新页面前保存在本地,重新打开时回复保存的内容。可以用 sessionStorage代替localStorage与session用户名绑定。
var Storage = (function () {
var $this
function storage() {
this.ini.apply(this, arguments)
}
storage.prototype = {
ini:function () {
$this = this
},
clear:function () {
window.localStorage.clear()
},
pri:function () {
for (var i = 0; i < localStorage.length; i++) {
document.write(localStorage.key(i) + " : " + localStorage.getItem(localStorage.key(i)) + "<br>");
}
}
}
var k = new storage()
k.pri()
}())
$(".ttd").click(function () {
localStorage.clear()
})
window.onbeforeunload = function () {
return false;
}
window.onunload = function () {
var k = $("#text").val()
localStorage.setItem("text", k)
}
$(document).ready(function () {
if (localStorage.text) {
$("#text").val(localStorage.text)
}
})
demo:http://fiddle.jshell.net/break_happy/ALzrB/4/show/light/

浙公网安备 33010602011771号