local storage 简单应用‘’记住密码’

前些时候一直用cookie等来进行登录页面记住面膜操作,但是由于其存储容量小等缘故,所以后来转向local storage,原理为:当用户勾选记住密码时,local storage 存储用户名密码同时存储记住密码checked,反之则为空;以下为我关于记住密码操作的代码分享

html部分

</head>
<body  >
<div class="container1">
    <div class="login">
        <img src="http://123.56.25.169:8099/esmp/img/log.png" alt=""/>
    </div>
</div>
<div id="middle">
    <div class="main">
        <div class="loginin rt" style="position: relative">
            <div class="header">
                <img src="http://123.56.25.169:8099/esmp/img/tip.png" alt=""/>
            </div>
                <div class="mainsection form-group">
                    <div style="width: 246px;height: 46px; margin-bottom: 18px">
                        <b class="lf markk"></b>
                        <input class="lf username" type="text" placeholder="用户名"
                               id="user" autofocus/>
                    </div>
                    <div style="width: 246px;height: 46px;">
                        <b class="lf markk markk1"></b>
                        <input class="lf username" type="password" placeholder="密码" autofocus id="password"/>
                    </div>
                </div>
                <div class="pw">
                    <div class="loadingstatus lf">
                    </div>
                    <div class="rt" style="font-size: 12px;color: #707070;line-height: 26px;">
                        <input type="checkbox" class="lf" id="autoLogin"/>
                        <span class="rem">
                        自动登录
                        </span>
                    </div>
                </div>
                <div class="footersection" style="text-align: center">
                    <button id="btn1">登 录</button>
                    <div class="registerhtml">
                        <span class="lf">没有账号?</span>
                        <a href="http://123.56.25.169:8099/esmp/register.html" class="lf">免费注册</a>
                    </div>
                </div>
        </div>

    </div>
</div>

</body>
</html>

js部分
//记住密码
if($('#autoLogin').is(':checked')) {
    localStorage.setItem('username', username);
    localStorage.setItem('password', password);
}else{
    localStorage.setItem('username', "");
    localStorage.setItem('password', "");
}

//记住密码end
//用户名密码value获取
$("#user").val(localStorage.getItem('username'));
$("#password").val(localStorage.getItem('password'));
if(localStorage.getItem('username')==""){
    $("#autoLogin").attr("checked",false)
}else{
    $("#autoLogin").attr("checked",true)
}
//用户名密码value获取end

 

转载于:https://www.cnblogs.com/bellagao/p/6264436.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值