我已经查看了有关同一问题的许多问题,但我仍然无法弄清楚我的代码出了什么问题。
HTML:
<form id="form" method="POST" onsubmit="return false;">
<input type="text" placeholder="First Name" id="first" /><br />
<input type="text" placeholder="Last name" id="last" /><br />
<input type="text" placeholder="Username" id="user" /><br />
<input type="text" placeholder="Email" id="email" /><br />
<input type="password" id="right" placeholder="Password" id="password" /><br />
<input type="password" id="right" placeholder="Confirm Password" id="confirm" /><br />
<button class="btn btn-block btn-lg" method="POST" onclick="signup()">Sign Up</button>
</form>
Javascript:
function signup() {
var f = document.getElementById("first").value;
var l = document.getElementById("last").value;
var user = document.getElementById("user").value;
var e = document.getElementById("email").value;
var p = document.getElementById("password").value;
var p1 = document.getElementById("confirm").value;
if (f == "" || l == "" || user == "" || e == "" || p == "" || p1 == "") {
alert("One or more fields are empty!");
} else {
alert("test");
}
}
谢谢大家。
最佳答案
<input ... id="right" ... id="password" />
密码和确认密码输入中的双 ID。
关于javascript - 无法读取 null、注册表单的属性 'value',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21503261/