前台通过window.localStorage存储用户名
var storage = window.localStorage; if ($("#rember").is(":checked")) { storage["name"] = $("#name").val(); storage["password"] = $("#password").val(); storage["isstorage"] = "yes"; alert(1); } else { storage["name"] = ""; storage["password"] = $("#password").val(); storage["isstorage"] = ""; alert(2); }
开始加载的时候判断是否已存储用户名:
var storage = window.localStorage; if ("yes" == storage["isstorage"]) { $("#rember").attr("checked", true); $("#name").val(storage["name"]); } else { $("#rember").attr("checked", false); $("#name").val(storage["name"]); }