我不知道为什么这个错误会在我的控制台中弹出,而不是我的脚本无效,我已将其包含在其中。 它在添加" form"之前运行良好。标签。 我得到的另一个错误是
"表单以windows-1252编码提交,无法对所有Unicode字符进行编码,因此用户输入可能会损坏。要避免此问题,应更改页面,以便通过将页面本身的编码更改为UTF-8或在表单元素上指定accept-charset = utf-8,以UTF-8编码提交表单。 "
<!doctype html>
<html lang="en">
<title>
LOG IN
</title>
<head>
</head>
<script >
function login()
{
var id,paswd,cpaswd;
id=document.getElementById("name").value;
paswd=document.getElementById("pass").value;
cpaswd=document.getElementById("confirmation").value;
if(paswd!=cpaswd)
{ alert("password don't match");
return false;
}
else
{ alert("successful")
return true;
}
}
</script>
<body>
<br>
<br>
<div align ="center" id="">
<form method="post" onsubmit="return login()" action="/calculator.html" >
<h1>REGISTRATION </h1>
<input type="text" placeholder="Name" id="name" autocomplete="off" ><br><br>
<input type="password" placeholder="Password" id="pass" required><br><br>
<input type="password" placeholder="Confirm Password" id="confirmation" required><br><br><br><br>
<button id="login" onclick="login()" type="submit" >REGISTER</button>
</form>
</body>
</html>
&#13;
答案 0 :(得分:0)
login
是您提交给提交按钮的id
,DOM元素存在于全局范围内,它会覆盖您的同名函数。更改功能名称和对其的调用(或按钮的id
)可以解决问题。
顺便说一下,由于您使用的是submit
按钮,因此您只需要/想要在表单的submit
事件上调用您的函数,而不是click
事件的function logins() {
var id, paswd, cpaswd;
id = document.getElementById("name").value;
paswd = document.getElementById("pass").value;
cpaswd = document.getElementById("confirmation").value;
if(paswd!=cpaswd) {
alert("password don't match");
return false;
} else {
alert("successful")
return true;
}
}
事件。按钮。
<form method="post" onsubmit="return logins()" action="/calculator.html" onsubmit="return login()" >
<h1>REGISTRATION </h1>
<input type="text" placeholder="Name" id="name" autocomplete="off" ><br><br>
<input type="password" placeholder="Password" id="pass" required><br><br>
<input type="password" placeholder="Confirm Password" id="confirmation" required><br><br><br><br>
<button id="login" type="submit" >REGISTER</button>
</form>
&#13;
Get-Module
&#13;