一般在管理平台的登录页中,当用户登录过一次的时候,下一次自动记住上一次输入的用户,直接输入密码即可登录,增加用户体验。

<script language="JavaScript"> 

$(function () {
    var storage = window.localStorage;
    if(storage["username"] != ''){
        $("#username").val(storage["username"]);
    }
    if (window != top) {
        top.layer.confirm('您长时间无操作,请重新登录!', {
              btn: ['确定'] //按钮
            }, function(){
                top.location.href = location.href; 
            });
    } 
});
</script>

登录成功之后保存在本地

function login(){
    var index;
    var options = {
            url : '<%=path%>/entry',
            type : 'post',
            dataType : 'json',
            beforeSubmit:function(){
                index = layer.load(0, {shade: [0.1,'#fff']});
            },
            success:function(data){
                console.log("code="+data.code);
                if(data.code=='0'){
                    storage["username"] = $("#username").val();
                    location.href="<%=path%>/home";
                }else if(data.code=='5001'){
                    layer.alert('账号不存在', {
                          title:'提示',
                        skin: 'layui-layer-lan'
                        ,closeBtn: 0
                        ,anim: 5 
                      });
                }else if(data.code=='5002'){
                    layer.alert('密码错误', {
                          title:'提示',
                        skin: 'layui-layer-lan'
                        ,closeBtn: 0
                        ,anim: 5 
                      });
                }else if(data.code=='5014'){
                    location.href="<%=path%>/importOrg";
                }else{
                    layer.alert('账号或者密码错误', {
                          title:'提示',
                        skin: 'layui-layer-lan'
                        ,closeBtn: 0
                        ,anim: 5 
                      });
                }
                layer.close(index);
            },
            error:function(req,status,error){
                layer.alert('请求超时', {
                      title:'提示',
                    skin: 'layui-layer-lan'
                    ,closeBtn: 0
                    ,anim: 5 
                  });
                layer.close(index);
            }
    };
    $("#hbkForm").ajaxSubmit(options);
}