本文主要是介绍jQuery插件——表单验证(jquery.validate.js),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
HTML
<form id="loginForm"><label class="form__label--hidden" for="username">用户名:</label><input class="form__input" type="text" id="username" name="username" placeholder="用户名"><label class="form__label--hidden" for="password">密码:</label><input class="form__input" type="password" id="password" name="password" placeholder="密码"><input class="form__btn" type="submit" value="登录">
</form><script src="js/jquery-1.7.1.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script>
$(document).ready(function() {$('#loginForm').validate({rules: {username: {required: true,minlength: 6,maxlength: 16},password: {required: true,minlength: 6,maxlength: 16}},messages: {username: {required: "必须填写用户名!",minlength: "用户名长度不能小于6位!",maxlength: "用户名长度不能大于16位!"},password: {required: "必须填写密码!",minlength: "密码长度不能小于6位!",maxlength: "密码长度不能大于16位!"}}});
});
</script>
这篇关于jQuery插件——表单验证(jquery.validate.js)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!