jscript中如何通过id号获取 imput text中的值

<!DOCTYPE html>
<html>
    <head>
        <title>stuLogin</title>
    </head>
    <body>
        <div>
            <h3>Student Login</h3>
            <div><label >Accounts: </label><input type="text" name="stuName" id="stuName"></div>
            <div><label >Password: </label><input type="password" name="stuKey" id="stuKey"></div>
            <div><input type="button" value="Login" id="button1"></div>
        </div>

        <script type="text/javascript">

            button1.addEventListener('click',function(){loginCheck();},false);
            function loginCheck(){
                var stuName=document.getElementById("stuName").value;//根据id名获取text中的值
                var stuKey=document.getElementById("stuKey").value;
                alert("Login Failed !"+stuName);
            }
            
        </script>
        
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/jzlStudent/article/details/104465848