日期:2014-05-16  浏览次数:20433 次

js验证两次输入密码是否一致
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>checkPwd</title>
		<meta name="author" content="yangch" />
		<!-- Date: 2013-06-20 -->
		<script>
			function check2pwd() {
					if(input1.value != input2.value) {
						alert("两次输入密码不一致!")
						input1.value = "";
						input2.value = "";
					}
			}
		</script>
	</head>
	<body>
		<form action="testaction">
			<table>
				<tr><td>密码:&nbsp;&nbsp;
				  <input type="password" id="input1"></td>
				</tr>
			    <tr><td>重复密码:
				  <input type="password" id="input2" onblur="check2pwd()" ></td></tr> 
				
			</table>
			<input type="button" value="test啦!" />
		</form>
		
	</body>
</html>