我不知道如何显示要求输入用户名和密码的信息!
当我单击“提交”时,它会自动打开到index.php
它应该显示我要求的用户名和密码
这是我的代码:
var username = document.form["vform"]["username"];
var email = document.form["vform"]["email"];
var password = document.form["vform"]["password"];
var password_confirmation = document.form["vform"]["password_confirmation"];
var name_error = document.getElementById("name_error");
var email_error = document.getElementById("email_error");
var password_error = document.getElementById("password_error");
username.addEventListener("blur", nameVerify, true);
email.addEventListener("blur", emailVerify, true);
password.addEventListener("blur", passwordVerify, true);
function Validate() {
if (username.value == "") {
username.style.border = "1px solid red";
name_error.textContent = "Username is required";
name.focus();
return false;
}
if (email.value == "") {
email.style.border = "1px solid red";
email_error.textContent = "Email is required";
email.focus();
return false;
}
if (password.value == "") {
password.style.border = "1px solid red";
password_error.textContent = "Password is required";
password.focus();
return false;
}
// Check if two password match
if (password.value != password_confirmation.value) {
password.style.border = "1px solid red";
password_confirmation.style.border = "1px solid red";
password_error.innerHTML = "The two passwords don't match";
return false;
}
}
function nameVerify() {
if (username.value != "") {
username.style.border = "1px solid #5E6E66";
name_error.innerHTML = "";
return true;
}
}
function emailVerify() {
if (email.value != "") {
email.style.border = "1px solid #5E6E66";
email_error.innerHTML = "";
return true;
}
}
function passwordVerify() {
if (password.value != "") {
password.style.border = "1px solid #5E6E66";
password_error.innerHTML = "";
return true;
}
}
我看不到错误,我认为这很好,没有语法错误,也许是缺少某些东西。
答案 0 :(得分:2)
确保您的表单具有required attribute(HTML5):
<input type="text" name="username" required />
<input type="text" name="password" required />
无需JavaScript验证。确保也在服务器端进行验证。