使用javascript转到另一个html页面

使用javascript转到另一个html页面,javascript,html,Javascript,Html,我有两个文件。一个是login.html,它是一个带有表单的简单html5文件 HTML <form method="post" action="" name="form1">entre the pasword: <input type="password" name="code" placeholder="code" maxlength="6"> <p class="submit"> <input type="submi

我有两个文件。一个是
login.html
,它是一个带有表单的简单html5文件

HTML

<form method="post" action="" name="form1">entre the pasword:
    <input type="password" name="code" placeholder="code" maxlength="6">
    <p class="submit">
        <input type="submit" name="commit" value="send" onclick="verif(document.form1.code)">
    </p>
</form>
现在我的问题是,当我输入密码时,如果它是错误的,则会出现提示错误的警告消息(它会出现,我对此没有问题),如果它是正确的,我会被重定向到下一页。第二部分不适合我


请帮帮我,我已经坚持了两天了。

因为你的按钮是一个提交按钮,我认为它是在JS完成后提交表单的,这可能是你没有被重定向到Test.html的原因(因为表单
操作
属性没有任何值)尝试下面的HTML表单代码,并检查这是否解决了问题

<form method="post" action="" name="form1" onsubmit="verif(document.form1.code);return false;">entre the pasword:
    <input type="password" name="code" placeholder="code" maxlength="6">
    <p class="submit">
        <input type="submit" name="commit" value="send">
    </p>
</form>
输入密码:


返回falseonsubmit
属性中的code>阻止表单的默认提交操作。无论何时提交表单(即单击“提交”按钮),都将执行
verif(document.form1.code)

到底什么不起作用?具体点。我已经提到了重定向不起作用…如果(inputText.value.match(pwd)){window.location.href='Test.html';}第一个测试没有将我发送到我想要的页面,它是否输入了if?您是否尝试过简单地
inputxt.value==pwd
?请注意,这是一种密码保护方法,除了学习之外,您不应该使用它。put
alert('redirect')就在
window.location.href='Test.html';}
查看您是否遇到了if块,并让我们知道..@neustre我确实尝试过,它在这里对我有效。您的控制台现在是否有其他错误?这是你的页面的完整代码吗?也许还有别的什么影响着你。
<form method="post" action="" name="form1" onsubmit="verif(document.form1.code);return false;">entre the pasword:
    <input type="password" name="code" placeholder="code" maxlength="6">
    <p class="submit">
        <input type="submit" name="commit" value="send">
    </p>
</form>