<<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>表单验证</title> <body> <form id="yz"> <fieldset> <legend>用户登录</legend> <P> <label for="username">用户名</label> <input type="text" id="username" name="username" /> </P> <p> <label for="password">密码</label> <input type="password" id="password" name="password" /> </p> <input type="submit" value="登录" /> </fieldset> </form> <script type="text/javascript" src="vendor\jquery.validate-1.13.1.js"></script> <script type="text/javascript" src="vendor\jquery-1.10.0.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#yz").validate({ debug:true, rules:{ username:{ reuqired:true, minlength:2, maxlength:10 }, password:{ reuqired:true, minlength:2, maxlength:16 } }, message:{ username:{ required: '请输入用户名', minlength: '用户名不能小于2个字符', maxlength: '用户名不能超过10个字符', }, password:{ required: '请输入密码', minlength: '密码不能小于2个字符', maxlength: '密码不能超过16个字符' } } }); }); </script> </body> </html>
rules里写错了,应该是required。