命令“window.location.href"不适用于 HTML(引导框架) [英] Command "window.location.href" not working on HTML (Bootstrap framework)
问题描述
我目前正在从事一个大学项目,我需要在其中创建一个简单的登录屏幕,将用户重定向到另一个登录页面.由于我是 Web 编程的新手,我搜索了一些函数,发现最常用的命令是 window.location.href
,它对我的代码不起作用.这是:
I'm currently working on a university project in which I need to create a simple login screen which redirects the user to another landing page. As I'm new to web programming, I searched some functions and found that the most used command is the window.location.href
, which simply doesn't work on my code. Here it is:
<button class="btn btn-lg btn-primary btn-block" type="submit" onclick="validation(this.form)">Sign in</button>
</form>
<script language = "Javascript">
function validation(form){
if(form.inputEmail.value=="user@user.com" && form.inputPassword.value=="user123"){
window.location.href('form.html');
}
else {
alert("Invalid e-mail or password.");
}
}
</script>
我已经检查了路径,但是当您输入有效的用户名和密码时唯一有效的方法是 window.open()
I've already checked the paths, but the only method that works when you enter the valid username and password is the window.open()
推荐答案
window.location.href
是一个属性而不是一个函数.将该值指定为绝对路径.
window.location.href
is a property not a function. Assign the value as an absolute path instead.
window.location.href = '/form.html';
还有一种函数风格的方法可以做到这一点,你可能会混淆它:
There is also a function style way of doing this which you might be confusing it with:
window.location.assign("form.html");
这篇关于命令“window.location.href"不适用于 HTML(引导框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!