[1] validate( [options] ) ·µ»Ø£ºValidator
˵Ã÷£º¼ûµÚÒ»²¿·Ö
[2] valid() ·µ»Ø£ºBoolean
˵Ã÷£º¼ì²é±íµ¥ÊÇ·ñÒÑͨ¹ýÑéÖ¤¡£ Js´úÂë
- $("#myform").validate();
- $("a.check").click(function() {
- alert("Valid: " + $("#myform").valid());
- return false;
- });
$("#myform").validate(); $("a.check").click(function() { alert("Valid: " + $("#myform").valid()); return false; });
[3] rules() ·µ»Ø£ºOptions
˵Ã÷£º·µ»ØÒ»¸ö±íµ¥ÔªËصÄÑéÖ¤¹æÔò¡£Óм¸¸ö·½·¨¶¨ÒåÑéÖ¤¹æÔò£º
- ÔÚ±íµ¥ÔªËصÄclassÊôÐÔÖж¨ÒåÑéÖ¤¹æÔò£¨ÍƼöµÄ·½·¨£©¡£
- ͨ¹ýÖ¸¶¨ÑéÖ¤·½·¨µÄÊôÐÔ£¨ÍƼöµÄ·½·¨£©¡£
- ¿ÉÒÔͨ¹ýÔªÊý¾Ý(metadata)²å¼þÀ´¶¨ÒåÔªÊý¾ÝÑéÖ¤¹æÔò¡£
- ¿ÉÒÔͨ¹ýÖ¸¶¨validate()·½·¨µÄrulesÑ¡Ïî¡£
Js´úÂë
- alert($("#password").rules()["required"]);
alert($("#password").rules()["required"]);
[4] rules( "add", rules ) ·µ»Ø£ºOptions
²ÎÊý"add" ÀàÐÍ£ºString
²ÎÊý rules ÀàÐÍ£ºOptions ÒªÌí¼ÓµÄ¹æÔò£¬Óëvalidate·½·¨ÖеÄÑéÖ¤¹æÔòÒ»Ö¡£
˵Ã÷£ºÌí¼Ó¹æÔòµ½Æ¥ÅäµÄ±íµ¥ÔªËØ£¬·µ»Ø¸ÃÔªËصÄËùÓÐÑéÖ¤¹æÔò£¬ÐèÒªÏÈÖ´ÐÐ$("form").validate()¡£ÔÚrulesÖÐÒ²¿ÉÒÔÌí¼ÓÓû§×Ô¶¨ÒåµÄÏûÏ¢¶ÔÏó¡£
- $("#myinput").rules("add", {
- required: true,
- minlength: 2,
- messages: {
- required: "Required input",
- minlength: jQuery.format("Please, at least {0} characters are necessary")
- }
- });
$("#myinput").rules("add", { required: true, minlength: 2, messages: { required: "Required input", minlength: jQuery.format("Please, at least {0} characters are necessary") } });
[5] rules( "remove", [rules] ) ·µ»Ø£ºOptions
²ÎÊý"remove" ÀàÐÍ£ºString
²ÎÊý rules (Options) ÀàÐÍ£ºOptions Óÿհ׷û·Ö¸îµÄÑéÖ¤¹æÔò¡£Ö»²Ù×÷ͨ¹ýrulesÑ¡Ïî»òrules("add")Ö¸¶¨µÄÑéÖ¤¹æÔò¡£
˵Ã÷£º´ÓµÚÒ»¸öÆ¥ÅäµÄ±íµ¥ÔªËØÖÐÒƳýÖ¸¶¨µÄÑéÖ¤¹æÔò£¬²¢·µ»Ø¸ÃÔªËØËùÓеÄÑéÖ¤¹æÔò¡£
- $("#myinput").rules("remove");
- $("#myinput").rules("remove", "min max");
$("#myinput").rules("remove"); $("#myinput").rules("remove", "min max");
[6] removeAttrs( attributes ) ·µ»Ø£ºOptions
²ÎÊý attributes ÀàÐÍ£ºString Óÿհ׷û·Ö¸îµÄÊôÐÔÁбí
˵Ã÷£º´ÓµÚÒ»¸öÆ¥ÅäµÄ±íµ¥ÔªËØÖÐɾ³ýÖ¸¶¨µÄÊôÐÔ²¢·µ»ØËüÃÇ¡£
- $("#skip").click(function() {
- var rules = $("#myinput").removeAttrs("min max");
- $("#myform).submit();
- $("#myinput").attr(rules);
- });