请给我一些JavasSript代码,以便我可以在更改密码时实施重新输入密码验证。
答案 0 :(得分:3)
非常简化,但可以在表单的submit事件上放置以下代码,以便在用户尝试保存时检查两个输入。
var password1 = document.getElementById("password1input"); // get a reference to the first input
var password2 = document.getElementById("password2input"); // get a reference to the second input
if (password1.value != password2.value) { // compare the values
alert("They don't match!"); // alert the user
return false; // prevent the form from submitting
}