我想使用表单进行简单的登录,我创建一个表单,其中包含输入字段,供用户输入密码,然后用户按下提交按钮
将使用javascrip检索密码,如果密码正确则会打开新页面
<script language="javascript">
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.password.value == "nopassword")
{
self.location='main.html'
}
else
{
alert("Wrong Password\nTry again Bak Choy Friend! :)")/*displays error message*/
}
}
</script>
.
.
.
<form>
<input type="text" placeholder="Password" name="password">
<input type="button" class="button" value="Login" onclick="check(this.form)"/>
</form>
但问题是它需要用户在打开新页面之前按两次而不是一次? 第一次,我按下带密码的按钮,地址栏显示
...净/?密码= NOPASSWORD
然后,第二次按下带有密码的按钮,它会将我重定向到新页面 我可以知道如何解决这个问题?
答案 0 :(得分:0)
试试这个:
<script language="javascript">
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.password.value === "nopassword")
{
self.location = 'main.html';
return true;
}
else
{
alert("Wrong Password\nTry again Bak Choy Friend! :)")/*displays error message*/
return false;
}
}
</script>
<input type="button" class="button" value="Login" onclick="return check(this.form);"/>