本篇文章给大家带来的内容是介绍jquery的validate.js表单验证插件如何使用(代码示例)。有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。
效果:

代码:
jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
html>
<meta>
<meta>
<meta>
<title>表单验证插件Validate</title>
<script></script>
<script></script>
<style>
body {
background-color: #000;
}
form {
width: 361px;
margin: 80px auto;
padding: 50px;
border: 2px solid #666;
box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
background-color: #999;
border-radius: 10px;
box-sizing: border-box;
}
form>p {
margin-bottom: 20px;
color: #fff;
}
form>p>label {
display: inline-block;
width: 80px;
text-align: center;
}
label.error {
display: block;
width: 100%;
color: rgb(189, 42, 42);
font-size: 12px;
text-align: right;
margin-top: 5px;
}
input {
width: 170px;
height: 20px;
outline: none;
background-color: #ddd;
border: 1px solid #ddd;
border-radius: 4px;
}
.submit {
width: 170px;
margin: 30px auto 0;
}
.submit input {
background-color: #0099aa;
color: #fff;
border: 0;
padding: 5px;
height: 30px;
}
</style>
<script>
$(function() {
$("#signupForm").validate({
rules: {
name: "required",
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
}
},
messages: {
name: "请输入姓名",
email: {
required: "请输入Email地址",
email: "请输入正确的Email地址"
},
password: {
required: "请输入密码",
minlength: "密码不能小于5个字符"
},
confirm_password: {
required: "请输入确认密码",
minlength: "确认密码不能小于5个字符",
equalTo: "两次输入的密码不一致"
}
}
});
})
</script>










