繁体   English   中英

如何“onclick="location.href=''" 用于 html 按钮,用于用户登录,仅在验证凭据后?

[英]How to "onclick="location.href=''" for html button, for user login, only after validating credentials?

我正在尝试为 Web 应用程序制作登录页面。 验证用户名和密码后,如何只允许 onclick="" 按钮?

以下是我所拥有的:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Customer Login</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="ch-cn">
<script>

    function validate() {
        var uname = document.getElementById("uname");
        var upass = document.getElementById("upass");
        if(uname.value == ""){
            alert("username can't be null");
            return false;
        }

        else if(upass.value ==""){
            alert("password can't be null");
            return false;
        }
        else
            return true;
    }

</script>
</head>
<body>
    This is the Customer login page.
    <br>
    <form method="post" action="custlogin">
        user SSN:<input type="text" id="uname" name="userSSN"><br>
        <br> password:<input type="password" id="upass" name="pwd"><br>
        <br>
        <button type="submit" value="submit" onclick="return validate();">submit</button>
        <button type="reset" value="reset">reset</button>
    </form>
</body>
</html>

您在哪里存储有效用户名和密码的信息? 一个数据库?

我试图提供帮助,但我不是专家。

据我了解,需要根据已保存在数据库中的值来测试输入的值。

就像是

具有 ID 为 userName 和 passWord 的表单字段

if {
userName == howeverYouReferenceAusernameindb
&& passWord == @tablename.columnName 
{
login code here
}
else { "please put valid creds"
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM