技术&日志

微信浏览器记住密码-localStorge

<script type="text/javascript">
        $(document).ready(function () {
            //读取 localStage 本地存储,填充用户名密码,如果自动登录有值直接跳转;    
            //相反,跳转到本页面,等待登陆处理    
            var storage = window.localStorage;
            var username = storage["username"];
            var getPwd = storage["password"];
            console.log(getPwd)
            var getisstroepwd = storage["isstorePwd"];
            if ("yes" == getisstroepwd) {
                $("#username").val(username);
                $("#password").val(getPwd);
                document.getElementById("isRemberPwdId").checked = true;
            }

        })

        $("form").submit( function () {
            login();
        } );
        function login() {
            var username = $("#username").val();
            var userPassWord = $("#password").val();
            console.log(username)
            console.log(userPassWord)
            if (username != "" && userPassWord != "") {

                var storage = window.localStorage;
                //记住密码    
                if (document.getElementById("isRemberPwdId").checked) {
                    //存储到loaclStage      
                    //alert(134);
                    storage["username"] = username;
                    storage["password"] = userPassWord;
                    storage["isstorePwd"] = "yes";
                }
                else {
                    storage["username"] = username;
                    storage["isstorePwd"] = "no";
                }
            }
        }

</script>

发表评论