[英]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>
单击注册按钮时,我想重定向到另一个 html 页面,并且 email 输入字段包含“@”并且密码输入字段值与重复密码相同,但我不知道我的代码有什么问题
查看脚本window.location.href
中的 window.location.href 以进行重定向。 如需更多参考,请查看https://www.w3schools.com/js/js_window_location.asp
按钮 onclick="email()" 括号是必需的,因为您在单击按钮时调用 function。
Function 无法访问在 function 之外声明的变量。 因此,在 function scope 中声明 email var。
它不是 email.include() function 它是 include()。 “s”不见了。 参考 - 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.