HTML
<form action="/s.php" method="post">
设置密码:<input type="password" id="p1" required>
确认密码:<input type="password" id="p2" required onblur="checkpassword()">
<input type="submit" value="提交">
</form>
JS
<script>
function checkpassword() {
var password = document.getElementById("p1").value;
var repassword = document.getElementById("p2").value;
if(password!=repassword){
alert("设置密码与确认密码不匹配!")
document.getElementById('p1').value = "";
document.getElementById('p2').value = "";
}
}
</script>