Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我运行这段代码时,它给了我错误的信息:login.js:12 uncaughttypeerror:cannotreadproperty';价值';HTMLInputElement.login(login.js:12)处的空值_Javascript_Null - Fatal编程技术网

Javascript 当我运行这段代码时,它给了我错误的信息:login.js:12 uncaughttypeerror:cannotreadproperty';价值';HTMLInputElement.login(login.js:12)处的空值

Javascript 当我运行这段代码时,它给了我错误的信息:login.js:12 uncaughttypeerror:cannotreadproperty';价值';HTMLInputElement.login(login.js:12)处的空值,javascript,null,Javascript,Null,查看您的代码,必须是getuser或getpassword设置为null。因此,localStorage.getItem(“用户名”)或localStorage.getItem(“用户名”)返回null let username = document.querySelector("username"); let password = document.querySelector("password"); let singinBtn = document.q

查看您的代码,必须是
getuser
getpassword
设置为null。因此,
localStorage.getItem(“用户名”)
localStorage.getItem(“用户名”)返回null

let username = document.querySelector("username");
let password = document.querySelector("password");
let singinBtn = document.querySelector("sing_in");
let getuser = localStorage.getItem("username");
let getpassword = localStorage.getItem("password");

if(singinBtn){
    singinBtn.addEventListener("click",login);

    function login(e){
        e.preventDefault();

        if(getuser.value==="" || getpassword.value===""){
            alert("please fill data");
        }
        else{ 
            if(getuser && getuser.trim===username.value.trim() && getpassword && getpassword.trim===password.value.trim())
            {
                setTimeout(()=>{ 
                    window.location="index.html";
                },1500);
            }
            else{
                alert("username or password wrong");
            }
        }
    }
}