![](/img/trans.png)
[英]OnClick HTML button : call Javascript function + location.href (Django)
[英]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.