简体   繁体   English

注册页面按钮没有将我重定向到另一个页面

[英]Signup page button isn't redirecting me to another page


<body>


<h1 style="color:red;">SIGN UP</h1>
<p style="color:blue;">Please fill in this form to create an account.</p>


  <label for="Email">Email:</label> 
  <input type="text" id="Email" name="Email"><br><br>
  <label for="password">password:</label>
  <input type="text" id="password" name="password"><br><br>
<label for="repeatpassword">repeatpassword:</label>
  <input type="text" id="repeatpassword" name="repeatpassword"><br><br>
<button onclick="email" >SIGNUP!</button>

  

    <script>
var email = document.getElementById("Email").value;


function email(){
if(document.getElementById("password").value===document.getElementById("repeatpassword").value && email.include("@")== true){
location.href = "question2.html";
}

}




</script>
</body>
</html>

I want to redirect to another html page when clicking on signup button and email input field contains "@" and password input field value is same as repeatpassword but I don't know what is wrong with my code单击注册按钮时,我想重定向到另一个 html 页面,并且 email 输入字段包含“@”并且密码输入字段值与重复密码相同,但我不知道我的代码有什么问题

Check out with window.location.href in the script function to redirect.查看脚本window.location.href中的 window.location.href 以进行重定向。 for more reference look out https://www.w3schools.com/js/js_window_location.asp如需更多参考,请查看https://www.w3schools.com/js/js_window_location.asp

  1. Button onclick="email()" parenthesis is required because you are calling a function on a button click.按钮 onclick="email()" 括号是必需的,因为您在单击按钮时调用 function。

  2. Function can't access a variable declared outside the function. Function 无法访问在 function 之外声明的变量。 So declare that email var inside the function scope.因此,在 function scope 中声明 email var。

  3. It's not email.include() function it's includes().它不是 email.include() function 它是 include()。 "s" was missing. “s”不见了。 Ref - https://www.w3schools.com/jsref/jsref_includes.asp参考 - https://www.w3schools.com/jsref/jsref_includes.asp

 function email(){ var email = document.getElementById("Email").value; if(document.getElementById("password").value===document.getElementById("repeatpassword").value && email.includes("@")== true){ console.log("Working"); } else{ console.log("Not working"); } }
 <h1 style="color:red;">SIGN UP</h1> <p style="color:blue;">Please fill in this form to create an account.</p> <label for="Email">Email:</label> <input type="text" id="Email" name="Email"><br><br> <label for="password">password:</label> <input type="text" id="password" name="password"><br><br> <label for="repeatpassword">repeatpassword:</label> <input type="text" id="repeatpassword" name="repeatpassword"><br><br> <button onclick="email()" >SIGNUP!</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM