[英]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.