jQuery¼¼Êõ

jQueryѧϰ֮·£¨8£©- ±íµ¥ÑéÖ¤²å¼þ-Validation£¬jquery-validation(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-12-24 12:03 ÎÒÒªÆÀÂÛ( )

µÚ¶þÖÖ·½Ê½£º×Ô¼ºÐ´ÌáʾÐÅÏ¢ 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 range

¡¡¡¡µÚ¶þÖÖ·½Ê½£º×Ô¼ºÐ´ÌáʾÐÅÏ¢

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 °üÆðÀ´

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • jqueryÈçºÎ½«Á½¸öÊý×éºÏ²¢

    jqueryÈçºÎ½«Á½¸öÊý×éºÏ²¢

    2016-12-25 11:01

  • jquery widget×é¼þ

    jquery widget×é¼þ

    2016-12-21 10:00

  • jQueryͼÏñ²Ã¼ô²å¼þJcropµÄ¼òµ¥Ê¹ÓÃ

    jQueryͼÏñ²Ã¼ô²å¼þJcropµÄ¼òµ¥Ê¹ÓÃ

    2016-12-20 12:02

  • jQuery ÖÐµÄ 39 ¸ö¼¼ÇÉ

    jQuery ÖÐµÄ 39 ¸ö¼¼ÇÉ

    2016-12-20 12:01

ÍøÓѵãÆÀ
¾