[英]JavaScript if condition isn't redirecting to another page
我有一個按鈕,當你點擊它時,它會啟動一個功能,該功能的目的是查看一堆陳述是否正確,如果是,它應該將我發送到另一個頁面
<a href="">
<button value="Registar" id="btn_registar" type="button" class="btn btn-default text-center" style="width: 90px; height: 30px; border-radius: 4px; cursor: pointer;" onclick="validar()">
<b>Registar</b></button>
</a> <p id="reg_off></p>
我的功能:
function validar(){
var nome = document.getElementById("nome").value;
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var conf_password = document.getElementById("conf_password").value;
//var idade = .... FALTA O CALCULO DA IDADE
if(nome == "" || username == "" || password == "" || conf_password == "")
{
//alert("NOT WORKING");
document.getElementById("reg_off").innerHTML = "ups";
//WHEN I USE THE BUTTON ON THIS CONDITIONS, THE MESSAGE APPEARS BUT IT ONLY SHOWS FOR LIKE A MICROSECOND
} else {
alert("WORKED");
window.location.href = "area_reservada.php";
}
}
將其更改為
window.location.href = "area_reservada.php";
應該有幫助
(但這會將 URL 設置為area_reservada.php
)因此您需要在其中插入完整的 URL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.