密码验证
一、案例演示
确认密码与输入的密码相同时验证成功可以提交
当输入的确认密码与密码不同时,不可以提交
二、实现步骤
1、verification.jsp
onblur 事件会在对象失去焦点时发生
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<script type="text/javascript" src="../js/jquery02.js"></script>
<body>
<script>
function verification() {
var pw1 = document.getElementById("repassword").value;
var pw2 = document.getElementById("password").value;
if(pw1 == pw2) {
document.getElementById("tishi").innerHTML="两次密码相同";
document.getElementById("button").disabled = false;
}
else {
document.getElementById("tishi").innerHTML="两次密码不相同";
document.getElementById("button").disabled = true;
}
}
</script>
<p id="tishi" style="color: red"></p>
<p>账号:<input type="text" name="name"><br></p>
<p>密码:<input type="text" id="password" onblur="verification()"><br></p>
<p>确认:<input type="text" id="repassword" onblur="verification()"></p>
<input id="button" type="submit" value="提交">
</body>
</html>