1

为什么“确认密码和密码相同”部分不起作用?意思是,使用' 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>
4

3 回答 3

1

你遗漏了

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

document.getElementById("confirmpassword").style.borderStyle = "solid";
于 2012-10-23T22:54:24.297 回答
0

设置borderWidth呢?是否设置不是很清楚。如果没有,例如,您应该设置为 1 像素。

于 2012-10-23T22:58:49.277 回答
0

您可以使用简单地设置标准边框style.border并尝试使其更具动态性,如果它始终是相同的配置,请看:

var border_style = "1px solid red";
document.getElementById("password").style.border = border_style;
document.getElementById("confirmpassword").style.border = border_style;
于 2016-04-12T18:48:10.430 回答