首先是判断浏览器是否支持这一属性,他是HTML5里的属性:
if(window.localStorage){
alert('支持');
}else{
alert('不支持');
}
localStorage.a = 3;//设置a为"3"
localStorage["a"] = "sfsf";//设置a为"sfsf",覆盖上面的值
localStorage.setItem("b","isaac");//设置b为"isaac"
var a1 = localStorage["a"];//获取a的值
var a2 = localStorage.a;//获取a的值
var b = localStorage.getItem("b");//获取b的值
localStorage.removeItem("c");//清除c的值
然后就是进登录页面填充
if (localStorage.key_id && localStorage.username)
{
$("#login_merchant_id").val(localStorage.key_id);
$("#login_username").val(localStorage.username);
} ;
账号密码正确时保存
localStorage.key_id = key_uni;
localStorage.username = username;