gpt4 book ai didi

javascript - 为什么 'confirm password and password' 同一部分不工作?

转载 作者:行者123 更新时间:2023-11-28 02:38:35 26 4
gpt4 key购买 nike

为什么“确认密码和密码相同”部分不起作用?意思是,使用“getElementById”来处理密码和确认密码的部分。每个部分都有效,但特定部分除外。它不会在文本字段周围显示红色框。谁能帮我吗?

<html>
<head>
</head>
<script>
function submitinfo()
{
var firstname = document.getElementById("firstname").value;
var lastname = document.getElementById("lastname").value;
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var confirmpassword = document.getElementById("confirmpassword").value;
var email = document.getElementById("email").value;

if(firstname !== "" && document.getElementById("firstname").style.borderColor == "red")
    {
    document.getElementById("firstname").style.border = "none"
    }

if(lastname !== "" && document.getElementById("lastname").style.borderColor == "red")
{
document.getElementById("lastname").style.border = "none"
}

if(username !== "" && document.getElementById("username").style.borderColor == "red")
{
document.getElementById("username").style.border = "none"
}

if(password !== "" && document.getElementById("password").style.borderColor == "red")
{
document.getElementById("password").style.border = "none"
}

if(confirmpassword !== "" && document.getElementById("confirmpassword").style.borderColor == "red")
{
document.getElementById("confirmpassword").style.border = "none"
}

if(email !== "" && document.getElementById("email").style.borderColor == "red")
{
document.getElementById("email").style.border = "none"
}

if(firstname == "")
{
document.getElementById("firstname").style.borderColor = "red";
document.getElementById("firstname").style.borderStyle = "solid";
}

if(lastname == "")
{
document.getElementById("lastname").style.borderColor = "red";
document.getElementById("lastname").style.borderStyle = "solid";
}

if(username == "")
{
document.getElementById("username").style.borderColor = "red";
document.getElementById("username").style.borderStyle = "solid";
}

if(password == "")
{
document.getElementById("password").style.borderColor = "red";
document.getElementById("password").style.borderStyle = "solid";
}

if(confirmpassword == "")
{
document.getElementById("confirmpassword").style.borderColor = "red";
document.getElementById("confirmpassword").style.borderStyle = "solid";
}

if(email == "")
{
document.getElementById("email").style.borderColor = "red";
document.getElementById("email").style.borderStyle = "solid";
}


if(password !== "" && confirmpassword !== "" && document.getElementById("password").style.border == "none" && document.getElementById("confirmpassword").style.border == "none" && password !== confirmpassword) { document.getElementById("password").style.border = "red"; document.getElementById("confirmpassword").style.border = "red"; }

if(firstname && lastname && username && password && confirmpassword && email !== "")
{
window.open()
}
}
</script>
<h><font size=4 color=3BCCBE><b>Full Name</b></font><h/>
<br>
<input type="text" id="firstname" size="15px" placeholder="First">
<input type="text" id="lastname" size="15px" placeholder="Last">
<br> <br> <br> <br>
<h><font size=4 color=3BCCBE><b>Choose your username</b></font></h>
<br>
<input type="text" id="username" size="37px">
<br>
<p><font size=3 color="grey">atleast 6 characters long</font></p>
<br>
<h><font size=4 color=3BCCBE><b>Create a password</b></font></h>
<br>
<input type="password" id="password" size="37px">
<br> <br> <br> <br>
<h><font size=4 color=3BCCBE><b>Confirm your password</b></font><h/>
<br>
<input type="password" id="confirmpassword" size="37px">
<br> <br> <br> <br>
<h><font size=4 color=3BCCBE><b>Email address</b></font><h/>
<br>
<input type="text" id="email" size="37px">
<br> <br> <br> <br>

<input type="button" value="Submit" onclick="submitinfo()" style="height:50px; width:85px; font-size:22px;>
<br>
</body>
</html>

最佳答案

你遗漏了

document.getElementById("password").style.borderStyle = "solid";

document.getElementById("confirmpassword").style.borderStyle = "solid";

关于javascript - 为什么 'confirm password and password' 同一部分不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13040541/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com