按照这里的教程,http://css-tricks.com/video-screencasts/96-localstorage-for-forms/。我能够使用提交按钮重新创建功能,但是,是否可以使用复选框而不是按钮?
这是我到目前为止所拥有的,
if (localStorage) {
$(function() {
// Insert new buttons
$("#savelinks")
.after("<input type='submit' value='Save Address' id='saveData'> ")
.after("<input type='submit' value='Clear Saved Address' id='clearData'>");
$("#saveData")
.click(function(e) {
e.preventDefault();
// Test if saved data exists on page load
localStorage.setItem("flag", "set");
var data = $("#form1").serializeArray();
// iterate over results
$.each(data, function(i, obj) {
localStorage.setItem(obj.name, obj.value);
});
});
if (localStorage.getItem("flag") == "set") {
var data = $("#form1").serializeArray();
$.each(data, function(i, obj) {
$("[name='" + obj.name +"']").val(localStorage.getItem(obj.name));
});
}
$("#clearData")
.click(function(e) {
e.preventDefault();
localStorage.setItem("flag", "");
});
});
}
先感谢您!