用javcscript记住用户名和密码保存在本地储存中,然后实现前端获取

<script type="text/javascript">

window.onload=function(){
 var Id = localStorage.getItem("txtId");

                    if(Id != null) //如果缓存中有数据,则加载出来 B5教程网
                    {
                        document.getElementById("txtId").value = Id;
                        document.getElementById("txtPwd").value = localStorage.getItem("txtPwd");
                        document.getElementById("chkRem").checked = "checked";
                    }
                    
                    }
                    //将账号与密码保存到Localstore
                    function remPwd() {
                        var check = document.getElementById("chkRem");
                        if(check.checked) //判断记住密码项是否勾选,是则记住密码到本地缓存
                        {
                            var id = document.getElementById("txtId").value;
                            var pwd = document.getElementById("txtPwd").value;
                            localStorage.setItem("txtId", id);
                            localStorage.setItem("txtPwd", pwd);
                        } else //否则就移除本地缓存
                        {
                            localStorage.removeItem("txtId");
                            localStorage.removeItem("txtPwd");
                        }
                    }



</script>
</head>

 <body class="bg-black">

        <div class="form-box" id="login-box" >
            <div class="header">登录页面</div>
            <form id="formLogin" action="user_loginApp.action" class="login" method="post">
                <div class="body bg-gray">
                    <div class="form-group">
                        <input type="text" name="loginName" id="txtId" class="form-control" placeholder="请输入用户名"   onblur="javascript:ok_or_errorBylogin(this)"/>
                    </div>
                    <div class="form-group">
                        <input type="password" name="password" id="txtPwd"class="form-control" placeholder="请输入密码" onBlur="javascript:ok_or_errorBylogin(this)" />
                    </div>         
                    
                    <div class="form-group">
                        <input type="checkbox"  checked="checked" id="chkRem" name="remember_me"/> 记住密码
                    </div>
                </div>
                <div class="footer">                                                               
                    <button type="submit" class="btn bg-olive btn-block" id="login"     
                    
                
            <hr>
             <p>
                 <b>
         XXXXXXX电子有限责任公司 </b> <br><b>XXXXXXXX有限责任公司<b> &nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;     联合开发<br /><b >&nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;电话:0771-3304546</b><br>
                                  
            
             </p>
            
            </div></form>

</body>
</html>