[英]window.location.replace() not working in a form
I'm trying to set up a login form who redirects the user to another page after submitting the form. 我正在尝试建立一个登录表单,该表单在提交表单后将用户重定向到另一个页面。 However neither
window.location.replace()
, window.location.href
, or window.open()
seem to work and I can't figure out why. 但是,
window.location.replace()
, window.location.href
或window.open()
都不起作用,我不知道为什么。 I checked on the developer tools and it gives me no error. 我检查了开发人员工具,它没有给我任何错误。
Here's the javascript: 这是JavaScript:
function loginUtente(){
var email = document.getElementById('loginemail').value;
var password = document.getElementById('loginpassword').value;
var utente = localStorage.getItem(email);
if( utente != null && JSON.parse(utente).password == password){
window.alert("login effettuato!");
window.location.replace("http:/www.google.it");
}
else{
window.alert("Utente o password non corretti");
}
return false;
}
And here's the HTML: 这是HTML:
<form class="form-group" id="formlogin" onsubmit="loginUtente()">
<label>Email</label>
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div>
<input id="loginemail" type="text" name="nome" class="form-control" placeholder="Indirizzo Email" required ></input>
</div>
<br>
<label>Password</label>
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
<input id="loginpassword" type="password" name="password" class="form-control" placeholder="Password" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success" ><span class="glyphicon glyphicon-send" ></span> Login</button>
</form>
Putting the return false
inside the if is not working either. 将
return false
放在if中也不起作用。 The Google url is of course a placeholder url. Google网址当然是占位符网址。
In the form tag you missed to add return statement : 在表单标记中,您错过添加return语句:
<form class="form-group" id="formlogin" onsubmit="return loginUtente()">
So, form is submitted without waiting for response of function. 因此,无需等待功能的响应即可提交表单。 and function code is not executed.
并且功能代码未执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.