¡¡¡¡µÚ¶þÖÖ·½Ê½£º×Ô¼ºÐ´ÌáʾÐÅÏ¢
1 $('#commentForm').validate({ 2 rules: { 3 4 firstname: { 5 required: true, 6 minlength: 5 7 }, 8 9 lastname: "required", 10 11 username: { 12 required: true, 13 rangelength: [4,6] 14 }, 15 16 password: { 17 required: true, 18 minlength: 4, 19 number: true 20 }, 21 22 confirm_password: { 23 required: true, 24 minlength: 3, 25 equalTo: '#password' 26 }, 27 28 email: { 29 required: true, 30 email: true 31 } 32 }, 33 messages: { 34 35 firstname: "ÇëÊäÈëÄúµÄÃû×Ö", 36 lastname: "ÇëÊäÈëÄúµÄÐÕÊÏ", 37 username: { 38 required: "ÇëÊäÈëÓû§Ãû", 39 minlength: "Óû§Ãû±ØÐèÓÉÁ½¸ö×Öĸ×é³É" 40 }, 41 password: { 42 required: "ÇëÊäÈëÃÜÂë", 43 minlength: "ÃÜÂ볤¶È²»ÄÜСÓÚ 5 ¸ö×Öĸ" 44 }, 45 confirm_password: { 46 required: "ÇëÊäÈëÃÜÂë", 47 minlength: "ÃÜÂ볤¶È²»ÄÜСÓÚ 5 ¸ö×Öĸ", 48 equalTo: "Á½´ÎÃÜÂëÊäÈë²»Ò»ÖÂ" 49 }, 50 email: "ÇëÊäÈëÒ»¸öÕýÈ·µÄÓÊÏä", 51 } 52 });
¡¡¡¡¡¡¡¡
¡¡¡¡Ð§¹û£º
¡¡¡¡×¢Ò⣺»¹ÓÐÒ»ÖÖдÑéÖ¤µÄ·½Ê½ÊÇÔÚ class ÖÐд£¬ÀýÈç
<input type="text">¡¡¡¡µ«ÊDz»ÍƼöÕâÖÖд·¨£¬ÒòΪ²»·ûºÏÑùʽÓë½á¹¹·ÖÀëµÄÒªÇ󣬲¢ÇÒ»¹ÐèÒª×Ô¼ºÏÂÔØÒ»¸öjquery.metadata.jsÎļþ²ÅÄܹ»ÕâÑùд
¨ˆ¨ˆ¨ˆ¨ˆ¨ˆ¨ˆ ±íµ¥Ìá½»ÎÊÌâ
¡¡¡¡¿ÉÒÔÔÚ±íµ¥Ìύ֮ǰִÐÐÎÒÃÇ×Ô¶¨ÒåµÄ´úÂ룬µ±ÎÒÃǵÄ×Ô¶¨Òå´úÂëÖ´ÐÐÍê±ÏºóÔÙÌá½»±íµ¥
1 $('#commentForm').validate({ 2 3 submitHandler: function(){ 4 alert("Ìύʼþ³É¹¦"); 5 from.submit(); 6 } 7 });¡¡¡¡¿ÉÒÔÉèÖÃvalidateµÄĬÈÏÖµ
1 $.validate.setDefaults({ 2 submitHandler: function(){ 3 alert("Ìá½»³É¹¦£¡"); 4 form.submit(); 5 } 6 });¡¡¡¡Ö»ÑéÖ¤²»Ìá½»±íµ¥
1 $(function(){ 2 $("#commentForm").validate({ 3 debug:true; 4 }); 5 });¨ˆ¨ˆ¨ˆ¨ˆ¨ˆ¨ˆ ´íÎóÌáʾÐÅÏ¢ÉèÖÃ
¡¡¡¡1¡¢´íÎóÐÅϢλÖÃÉèÖÃ
¡¡¡¡errorPlacement·½·¨ÊÇÉèÖôíÎóÐÅÏ¢ÏÔʾÔÚÄÄ£¬Ä¬ÈÏÖµÊÇÔÚÑéÖ¤ÔªËصĺóÃæ
1 errorPlacement: function(error, element) { 2 error.appendTo(element.parent()); 3 }¡¡¡¡errorClass ÊÇÉèÖôíÎóÐÅÏ¢µÄÑùʽ£¬ºó¸úcssÀàÃû
¡¡¡¡errorElement ÊÇÉèÖÃÓÃʲô±êÇ©°üס´íÎóÐÅÏ¢£¬Ä¬ÈÏÖµÊÇ<label>
¡¡¡¡errorLabelContainer ÊÇÉèÖý«ËùÓеĴíÎóÐÅÏ¢°üÔÚÒ»¸öµØ·½
¡¡¡¡wrapper ÊÇÉèÖÃÓÃʲô±êÇ©ÔÙ°ÑÉÏ±ßµÄ errorELement °üÆðÀ´
¡¡