簡體   English   中英

HTML5自定義驗證無法正常工作

[英]HTML5 custom validation not working properly

我具有以下功能來驗證2個密碼輸入字段之間的匹配。 當我提交表單時,即使密碼匹配,也會出現錯誤,而且我不明白問題出在哪里。 你們可以看看嗎? 謝謝

function checkPwdMatch() {

if (document.getElementById('password').value !=document.getElementById('confirm_password').value) {
document.getElementById('confirm_password').setCustomValidity('Two Passwords must match.');
} else {
document.getElementById('confirm_password').setCustomValidity('');
}

}

----表格字段----

<input class="form-control" type="password" placeholder="Password" id="password" name="password" value="" required>

<input class="form-control" type="password" placeholder="<?php echo $lang["joinRepeatPassword"]?>" value="" id="confirm_password" name="confirm_password"  required>

您確定HTML代碼中沒有其他具有相同ID(密碼或Confirm_Password)的元素嗎?


當我有這樣的HTML

<!doctype html>
<html>
<head>
<script>


function checkPwdMatch() {

if (document.getElementById('password').value !=document.getElementById('confirm_password').value) {
document.getElementById('confirm_password').setCustomValidity('Two Passwords must match.');
} else {
document.getElementById('confirm_password').setCustomValidity('');
}

}
</script>
</head>
<body>
<form method="post">
<input class="form-control" type="password" placeholder="Password" id="password" name="password" value="" required>

<input class="form-control" type="password" placeholder="password copy" value="" id="confirm_password" name="confirm_password"  onblur="checkPwdMatch()"  required>


<input type="submit" />
</form>
</body>
</html>

如果我將aaa和bbb放在兩個輸入中,則表明它們是無效的,當我將aaa和aaa放入時,一切似乎正常。 如果問題出在您發送表格和頁面刷新后,您需要發送更多詳細信息,我認為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM