로컬에 세 개의 데이터를 저장하고localstrage에 저장하며 최신 존재수 그룹 첫 번째

2025 단어
$(function () {

        // 
        var userarry = JSON.parse(localStorage.getItem("user"));
        if (userarry != null) {
            /*$("#name").val(userarry[0].username);
            $("#password").val(userarry[0].password);*/
        }


        $("#loginbtn").click(function () {

            var name = $("#name").val();
            var password = $("#password").val();
            if (name.length > 40 || !name) {
                alert(" ")
            } else if (password.length > 40 || !password) {
                alert(" ");
            } else {
                localStorage.setItem("islogin", "true");

                /***************** 3 **********************/
                // 
                var userarry = JSON.parse(localStorage.getItem("user"));
                // 
                if (userarry == null) {
                    userarry = Array();
                }
                // 
                if (userarry.length > 2) {
                    userarry.length = 2;// 
                }
                // 
                var user = {
                    username: name,
                    password: password
                };
                // 
                userarry.unshift(user);

                /* console.log(userarry[0].username);*/

                // 
                localStorage.setItem("user", JSON.stringify(userarry));
                /******************** 3 ****************************/
                
                var height = document.body.scrollHeight;// 
                $(".mengban").css("height",height);// 
                $(".mengban").show();
                setTimeout(function(){
                    $(".mengban").hide();
                    window.location.href = "personinfo.html";
                    
                },1000);// 1s 
                
            }

        });

    });

좋은 웹페이지 즐겨찾기