我有这段代码:
function pWordValidate() {
var pWord = document.getElementById("password");
if (pWord.value.length < 6 || pWord.value.length > 20) {
errorList("password must be between 6 - 20 length");
}
pWordValidate2(pWord);
}
function pWordValidate2(pWord) {
var pWord2 = document.getElementById("retypepassword");
if (pWord2 != pWord) {
errorList("passwords do not match");
}
showErrors();
}
当我尝试输出&#34; pWord&#34;在调用第二个函数的行上方,我得到&#34; objectHTMLInputElement&#34;
的输出答案 0 :(得分:1)
该行
if (pWord2 != pWord) {
应该是
if (pWord2.value != pWord.value) {
实际上pWord
和pWord2
都是DOM对象,您需要对其进行比较。