Last active
January 3, 2018 07:27
-
-
Save xlui/55363a88473ffa80534027795dc7cc42 to your computer and use it in GitHub Desktop.
Using jQuery to confirm password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Use jQuery to Confirm Password</title> | |
</head> | |
<body> | |
<form id="register" class="form-register" onsubmit="register();" method="post"> | |
<label for="username">用户名:</label> | |
<input id="username" type="text" placeholder="请输入用户名" required autofocus/> | |
<br/> | |
<label for="password">密码:</label> | |
<input id="password" type="password" placeholder="请输入密码" required/> | |
<br/> | |
<label for="passwordAgain">确认密码:</label> | |
<input id="passwordAgain" type="password" placeholder="请确认密码" required/> | |
<br/> | |
<button type="submit">注册</button> | |
</form> | |
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function () { | |
$('#register').validate({ | |
rules: { | |
password: { | |
required: true | |
}, | |
passwordAgain: { | |
required: true, | |
equalTo: "#password" | |
} | |
}, | |
messages: { | |
password: "请输入密码!", | |
passwordAgain: { | |
required: "请重新输入密码", | |
equalTo: "两次密码不一致!" | |
} | |
} | |
}); | |
}); | |
function register() { | |
alert("成功注册!"); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment