我的问题是当该人填写表格时,此页面说好,放开它,它不运行操作表格并转到welcome.html

时间:2019-05-04 17:33:57

标签: javascript html

这是带有JavaScript的index.html,然后单击“注册”按钮,显示错误消息或确定,但不欢迎html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Log in</title>
    <link rel="stylesheet" href="style_login.css">
    </head>
    <body>
    <div id="messageER"></div>
     <div id="register">
    <form name="login" action="" method="post" id="frmRegister" >
    <input type="text" name="FName" id="FName" placeholder="First Name"/>
    <input type="text" name="LName" id="LName" placeholder="Last Name"/>
    <input type="text" name="userName" id="userName" placeholder="User 
           Name"/>
    <input type="password" name="password" id="password" 
        placeholder="Password"/>

          </form>
            <button type="submit" name="btnRegister" id="btnRegister" 
       value="Register" onclick="submitclick()"  >Register</button>

           </div>
             <div id="messageOk"></div>
       <script>

           function submitclick() {
     var firstName = document.querySelector("#FName");
     var lastName = document.querySelector("#LName");
      var userName = document.querySelector("#userName");
      var password = document.querySelector("#password");
      if(firstName.value === "" && lastName.value === "" && userName.value 
      === "" && password.value === ""){
        let massageError = "The all of them is empty";
        let fillerror = document.querySelector("#messageER").innerHTML = 
       massageError;
        let massageok = "";
        let fillok = document.querySelector("#messageOk").innerHTML = 
        massageok;
        let myform = document.login;
        let mf = myform.removeAttribute("action");
        return false;


         }else if(firstName.value === ""){

        let massageError = "Please Enter your firstName";
        let fillerror = document.querySelector("#messageER").innerHTML = 
         massageError;
         let massageok = "";
        let fillok = document.querySelector("#messageOk").innerHTML = 
         massageok;
        let myform = document.login;
        let mf = myform.removeAttribute("action");
        return false;

                }else if(lastName.value === ""){

        let massageError = "Please Enter your lastName";
        let fillerror = document.querySelector("#messageER").innerHTML = 
            massageError;
        let massageok = "";
        let fillok = document.querySelector("#messageOk").innerHTML = 
        massageok;
        let myform = document.login;
        let mf = myform.removeAttribute("action");
        return false;

              }else if(userName.value === ""){

        let massageError = "Please Enter your userName";
        let fillerror = document.querySelector("#messageER").innerHTML = 
            massageError;
        let massageok = "";
        let fillok = document.querySelector("#messageOk").innerHTML = 
         massageok;
        let myform = document.login;
        let mf = myform.removeAttribute("action");
        return false;

             }else if(password.value === ""){

        let massageError = "Please Enter your password";
        let fillerror = document.querySelector("#messageER").innerHTML = 
          massageError;
        let massageok = "";
        let fillok = document.querySelector("#messageOk").innerHTML = 
         massageok;
        let myform = document.login;
        let mf = myform.removeAttribute("action");
        return false;

                  }
               let massageok = "Ok Let's go";
              let fillok = document.querySelector("#messageOk").innerHTML 
          = massageok;
              let massageError = "";
              let fillerror = 
        document.querySelector("#messageER").innerHTML = massageError;

           let mf = document.login.setAttribute("action","welcome.html");
           return mf;

             return true;
                    }
               </script>
                      </body>
                           </html>

welcome .html:索引html不要转到欢迎html 如果我在表单页面中定义了提交,则不会说或不显示消息 显示消息错误或确定的速度非常快

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Welcome</title>
    </head>
    <body>
    <h1>Welcome</h1>
    </body>
    </html>

请帮助我

1 个答案:

答案 0 :(得分:0)

我在标签内放置了提交按钮,它对我来说很好用。我打开了一个名为welcome.html的新html进行检查,它工作得很好。

Card