jQuery.validate.js API

来源:http://blog.csdn.net/azheng270/article/details/5135676


=================================================================

[javascript]  view plain copy
  1. jQuery.validate.js API  
  2. Name    Type  
  3. validate( options ) Returns: Validator  
  4. 验证所选的FORM  
  5. valid( )    Returns: Boolean  
  6. 检查是否验证通过  
  7. rules( )    Returns: Options  
  8. 返回元素的验证规则  
  9. rules( "add", rules )   Returns: Options  
  10. 增加验证规则。  
  11. rules( "remove", rules )    Returns: Options  
  12. 删除验证规则  
  13. removeAttrs( attributes )   Returns: Options  
  14. 删除特殊属性并且返回他们  
  15. Custom selectors  
  16. Name    TypeCustom selectors:  
  17.    
  18.    
  19.    
  20. Name    Type  
  21. :blank  Returns: Array <Element >  
  22. 没有值的筛选器  
  23. :filled Returns: Array <Element >  
  24. 有值的筛选器  
  25. :unchecked  Returns: Array <Element >  
  26. 没选择的元素的筛选器  
  27. Utilities  
  28. Name    TypeString utilities:  
  29.    
  30. Name    Type  
  31. jQuery.format( template, argument , argumentN... )  Returns: String  
  32. 用参数代替模板中的 {n}。  
  33.    
  34. Validator  
  35. validate方法返回一个Validator对象, 它有很多方法, 让你能使用引发校验程序或者改变form的内容. validator对象有很多方法, 但下面只是列出常用的.  
  36. Name    TypeValidator methods:  
  37.    
  38.    
  39.    
  40.    
  41.    
  42.    
  43.    
  44. Name    Type  
  45. form( ) Returns: Boolean  
  46. 验证form返回成功还是失败  
  47. element( element )  Returns: Boolean  
  48. 验证单个元素是成功还是失败  
  49. resetForm( )    Returns: undefined  
  50. 把前面验证的FORM恢复到验证前原来的状态  
  51. showErrors( errors )    Returns: undefined  
  52. 显示特定的错误信息  
  53. There are a few static methods on the validator object:  
  54. Name    TypeValidator functions:  
  55.    
  56. Name    Type  
  57. setDefaults( defaults ) Returns: undefined  
  58. 改变默认的设置  
  59. addMethod( name, method, message )  Returns: undefined  
  60. 添加一个新的验证方法. 必须包括一个独一无二的名字,一个JAVASCRIPT的方法和一个默认的信息  
  61. addClassRules( name, rules )    Returns: undefined  
  62. 增加组合验证类型 在一个类里面用多种验证方法里比较有用  
  63. addClassRules( rules )  Returns: undefined  
  64. 增加组合验证类型 在一个类里面用多种验证方法里比较有用,这个是一下子加多个[edit ]  
  65. List of built-in Validation methods  
  66. A set of standard validation methods is provided:  
  67. Name    TypeMethods:  
  68.    
  69. Name    Type  
  70. required( ) Returns: Boolean  
  71. 必填验证元素  
  72. required( dependency-expression )   Returns: Boolean  
  73. 必填元素依赖于表达式的结果.  
  74. required( dependency-callback ) Returns: Boolean  
  75. 必填元素依赖于回调函数的结果.  
  76. remote( url )   Returns: Boolean  
  77. 请求远程校验。url通常是一个远程调用方法  
  78. minlength( length ) Returns: Boolean  
  79. 设置最小长度  
  80. maxlength( length ) Returns: Boolean  
  81. 设置最大长度  
  82. rangelength( range )    Returns: Boolean  
  83. 设置一个长度范围[min,max]  
  84. min( value )    Returns: Boolean  
  85. 设置最小值.  
  86. max( value )    Returns: Boolean  
  87. 设置最大值.  
  88. range( range )  Returns: Boolean  
  89. 设置值的范围  
  90. email( )    Returns: Boolean  
  91. 验证电子邮箱格式  
  92. url( )  Returns: Boolean  
  93. 验证连接格式  
  94. date( ) Returns: Boolean  
  95. 验证日期格式(类似30/30/2008的格式,不验证日期准确性只验证格式)  
  96. dateISO( )  Returns: Boolean  
  97. 研制ISO类型的日期格式  
  98. dateDE( )   Returns: Boolean  
  99. 验证德式的日期格式(29.04.1994 or 1.1.2006)  
  100. number( )   Returns: Boolean  
  101. 验证十进制数字(包括小数的)  
  102. numberDE( ) Returns: Boolean  
  103. Makes the element require a decimal number with german format.  
  104. digits( )   Returns: Boolean  
  105. 验证整数  
  106. creditcard( )   Returns: Boolean  
  107. 验证信用卡号  
  108. accept( extension ) Returns: Boolean  
  109. 验证相同后缀名的字符串  
  110. equalTo( other )    Returns: Boolean  
  111. 验证两个输入框的内容是否相同  
  112.    
  113.    
  114. Name    Type  
  115. phoneUS( )  Returns: Boolean  
  116. 验证美式的电话号码  
  117.    
  118.    
  119.    
  120.    
  121.    
  122. validate ()的可选项  
  123. debug:进行调试模式  
  124. $(".selector").validate  
  125. ({  
  126.    debug: true  
  127. })  
  128.   把调试设置为默认  
  129.    
  130. $.validator.setDefaults({  
  131.    debug: true  
  132. })  
  133.    
  134. submitHandler:用其他方式替代默认的SUBMIT,比如用AJAX的方式提交  
  135.    
  136. $(".selector").validate({  
  137.    submitHandler: function(form) {  
  138.     $(form).ajaxSubmit();  
  139.    }  
  140. })  
  141.    
  142. ignore:忽略某些元素不验证  
  143. $("#myform").validate({  
  144.    ignore: ".ignore"  
  145. })  
  146.    
  147. rules: 默认下根据form的classes, attributes, metadata判断,但也可以在validate函数里面声明  
  148. Key/value 可自定义规则. Key是对象的名字 value是对象的规则,可以组合使用 class/attribute/metadata rules.  
  149. 以下代码特别验证selector类中name='name'是必填项并且 email是既是必填又要符合email的格式  
  150.    
  151. $(".selector").validate({  
  152.    rules: {  
  153.      // simple rule, converted to {required:true}  
  154.      name: "required",  
  155.      // compound rule  
  156.      email: {  
  157.        required: true,  
  158.        email: true  
  159.      }  
  160.    }  
  161. })  
  162.    
  163. messages:更改默认的提示信息  
  164.    
  165. $(".selector").validate({  
  166.    rules: {  
  167.      name: "required",  
  168.      email: {  
  169.        required: true,  
  170.        email: true  
  171.      }  
  172.    },  
  173.    messages: {  
  174.      name: "Please specify your name",  
  175.      email: {  
  176.        required: "We need your email address to contact you",  
  177.        email: "Your email address must be in the format of name@domain.com"  
  178.      }  
  179.    }  
  180. })  
  181. groups:定义一个组,把几个地方的出错信息同意放在一个地方,用error Placement控制把出错信息放在哪里  
  182.    
  183. $("#myform").validate({  
  184.   groups: {  
  185.     username: "fname lname"  
  186.   },  
  187.   errorPlacement: function(error, element) {  
  188.      if (element.attr("name") == "fname" || element.attr("name") == "lname" )  
  189.        error.insertAfter("#lastname");  
  190.      else  
  191.        error.insertAfter(element);  
  192.    },  
  193.    debug:true  
  194.  })  
  195.    
  196. nsubmit Boolean Default: true  
  197. 提交时验证. 设置唯false就用其他方法去验证  
  198. Code  
  199. 不用onsubmit验证,就允许用户无论用什么方法去验证,而是提交时, 用 keyup/blur/click 等方法.  
  200. $(".selector").validate({  
  201.    onsubmit: false  
  202. })  
  203. onfocusout  Boolean Default: true  
  204. Validate elements (except checkboxes/radio buttons) on blur. If nothing is entered, all rules are skipped, except when the field was already marked as invalid.  
  205. Code  
  206. Disables onblur validation.  
  207. $(".selector").validate({  
  208.    onfocusout: false  
  209. })  
  210. onkeyup Boolean Default: true  
  211. 在keyup时验证. As long as the field is not marked as invalid, nothing happens. Otherwise, all rules are checked on each key up event.  
  212. Code  
  213. Disables onkeyup validation.  
  214. $(".selector").validate({  
  215.    onkeyup: false  
  216. })  
  217. onclick Boolean Default: true  
  218. 在checkboxes 和 radio 点击时验证.  
  219. Code  
  220. Disables onclick validation of checkboxes and radio buttons.  
  221. $(".selector").validate({  
  222.    onclick: false  
  223. })  
  224. focusInvalid    Boolean Default: true  
  225. 把焦点聚焦在最后一个动作或者最近的一次出错上via validator.focusInvalid(). The last active element is the one that had focus when the form was submitted, avoiding to steal its focus. If there was no element focused, the first one in the form gets it, unless this option is turned off.  
  226. Code  
  227. Disables focusing of invalid elements.  
  228. $(".selector").validate({  
  229.    focusInvalid: false  
  230. })  
  231. focusCleanup    Boolean Default: false  
  232. 如果是true那么删除出错类从出错的元素上并且隐藏出错信息当这个元素被聚焦 .避免和 focusInvalid.一起用  
  233. Code  
  234. Enables cleanup when focusing elements, removing the error class and hiding error messages when an element is focused.  
  235. $(".selector").validate({  
  236.    focusCleanup: true  
  237. })  
  238. meta    String    
  239. 为了元数据使用其他插件你要包装 你的验证规则 在他们自己的项目中可以用这个特殊的选项  
  240. Tell the validation plugin to look inside a validate-property in metadata for validation rules.  
  241. $("#myform").validate({  
  242.    meta: "validate",  
  243.    submitHandler: function() { alert("Submitted!") }  
  244. })  
  245. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  246. <html>  
  247. <head>  
  248.   <mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>  
  249.     
  250.   <mce:script type="text/javascript"><!--  
  251.   $(document).ready(function(){  
  252.     $("#myform").validate({  
  253.      meta: "validate",  
  254.      submitHandler: function() { alert("Submitted!") }  
  255.     })  
  256.   });  
  257.     
  258. // --></mce:script>  
  259.     
  260. </head>  
  261. <body>  
  262.   <mce:script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/lib/jquery.metadata.js" mce_src="http://dev.jquery.com/view/trunk/plugins/validate/lib/jquery.metadata.js"></mce:script>  
  263.   <mce:script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" mce_src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></mce:script>  
  264. <form id="myform">  
  265.   <input type="text" name="email" class="{validate:{ required: true, email:true }}" />  
  266.   <br/>  
  267.   <input type="submit" value="Submit" />  
  268. </form>  
  269. </body>  
  270. </html>  
  271. errorClass  String  Default: "error"  
  272. 创建错误类的名字为了去寻找存在的错误标签和增加它到验证失败的元素中去。  
  273. Code  
  274. Sets the error class to "invalid".  
  275. $(".selector").validate({  
  276.    errorClass: "invalid"  
  277. })  
  278. errorElement    String  Default: "label"  
  279. 设置错误的元素,默认的是label你可以改成em.Use this element type to create error messages and to look for existing error messages. The default"label", has the advantage of creating a meaningful link between error message and invalid field using the for attribute (which is always used, no matter the element type).  
  280. Code  
  281. Sets the error element to "em".  
  282. $(".selector").validate  
  283.    errorElement: "em"  
  284. })  
  285. wrapper String    
  286. 在出错信息外用其他的元素包装一层。Wrap error labels with the specified element. Useful in combination with errorLabelContainer to create a list of error messages.  
  287. Code  
  288. Wrap each error element with a list item, useful when using an ordered or unordered list as the error container.  
  289. $(".selector").validate({  
  290.    wrapper: "li"  
  291. })  
  292. errorLabelContainer Selector      
  293. 把错误信息统一放在一个容器里面。Hide and show this container when validating.  
  294. All error labels are displayed inside an unordered list with the ID "messageBox", as specified by the selector passed as errorContainer option. All error elements are wrapped inside an li element, to create a list of messages.  
  295. $("#myform").validate({  
  296.    errorLabelContainer: "#messageBox",  
  297.    wrapper: "li",  
  298.    submitHandler: function() { alert("Submitted!") }  
  299. })  
  300. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  301. <html>  
  302. <head>  
  303.   <mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>  
  304.     
  305.   <mce:script type="text/javascript"><!--  
  306.     $(document).ready(function(){  
  307.       $("#myform").validate({  
  308.         errorLabelContainer: "#messageBox",  
  309.         wrapper: "li",  
  310.         submitHandler: function() { alert("Submitted!") }  
  311.       })  
  312.     });  
  313.     
  314. // --></mce:script>  
  315.     
  316. </head>  
  317. <body>  
  318.   <mce:script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" mce_src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></mce:script>  
  319. <ul id="messageBox"></ul>   
  320.  <form id="myform" action="/login" method="post">   
  321.    <label>Firstname</label>   
  322.    <input name="fname" class="required" />   
  323.    <label>Lastname</label>   
  324.    <input name="lname" title="Your lastname, please!" class="required" />   
  325.    <br/>  
  326.    <input type="submit" value="Submit"/>  
  327.  </form>  
  328. </body>  
  329. </html>  
  330. errorContainer  Selector      
  331. 显示或者隐藏验证信息  
  332. 使用一个额外的容器去显示错误信息  
  333. Uses an additonal container for error messages. The elements given as the errorContainer are all shown and hidden when errors occur. But the error labels themselve are added to the element(s) given as errorLabelContainer, here an unordered list. Therefore the error labels are also wrapped into li elements (wrapper option).  
  334. $("#myform").validate({  
  335.    errorContainer: "#messageBox1, #messageBox2",  
  336.    errorLabelContainer: "#messageBox1 ul",  
  337.    wrapper: "li", debug:true,  
  338.    submitHandler: function() { alert("Submitted!") }  
  339. })  
  340. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  341. <html>  
  342. <head>  
  343.   <mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>  
  344.     
  345.   <mce:script type="text/javascript"><!--  
  346.   $(document).ready(function(){  
  347.     $("#myform").validate({  
  348.        errorContainer: "#messageBox1, #messageBox2",  
  349.        errorLabelContainer: "#messageBox1 ul",  
  350.        wrapper: "li", debug:true,  
  351.        submitHandler: function() { alert("Submitted!") }  
  352.     })  
  353.   });  
  354.     
  355. // --></mce:script>  
  356.   <mce:style><!--  
  357. #messageBox1, #messageBox2 { display: none }  
  358. --></mce:style><style mce_bogus="1">#messageBox1, #messageBox2 { display: none }</style>  
  359. </head>  
  360. <body>  
  361.   <mce:script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" mce_src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></mce:script>  
  362. <div id="messageBox1">   
  363.   <ul></ul>   
  364. </div>   
  365. <form id="myform" action="/login" method="post">   
  366.   <label>Firstname</label>   
  367.   <input name="fname" class="required" />   
  368.   <label>Lastname</label>   
  369.   <input name="lname" title="Your lastname, please!" class="required" />  
  370.   <br/>  
  371.   <input type="submit" value="Submit"/>  
  372. </form>   
  373. <div id="messageBox2">   
  374.   <h3>There are errors in your form, see details above!</h3>   
  375. </div>  
  376. </body>  
  377. </html>  
  378. showErrors  Callback    Default: None, uses built-in message disply.  
  379. 得到错误的显示句柄  
  380.  Gets the map of errors as the first argument and and array of errors as the second, called in the context of the validator object. The arguments contain only those elements currently validated, which can be a single element when doing validation onblur/keyup. You can trigger (in addition to your own messages) the default behaviour by calling this.defaultShowErrors().  
  381. Code  
  382. Update the number of invalid elements each time an error is displayed. Delegates to the default implementation for the actual error display.  
  383. $(".selector").validate({  
  384.    showErrors: function(errorMap, errorList) {  
  385.     $("#summary").html("Your form contains " + this.numberOfInvalids() + " errors, see details below.");  
  386.     this.defaultShowErrors();  
  387.    }  
  388. })  
  389. errorPlacement  Callback    Default: 把错误label放在验证的元素后面  
  390. 可选错误label的放置位置. First argument: The created error label as a jQuery object. Second argument: The invalid element as a jQuery object.  
  391. Use a table layout for the form, placing error messags in the next cell after the input.  
  392. $("#myform").validate({  
  393.   errorPlacement: function(error, element) {  
  394.      error.appendTo( element.parent("td").next("td") );  
  395.    },  
  396.    debug:true  
  397.  })  
  398. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  399. <html>  
  400. <head>  
  401.   <mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>  
  402.   <mce:script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" mce_src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></mce:script>  
  403.   <mce:script type="text/javascript"><!--  
  404.   $(document).ready(function(){  
  405.     $("#myform").validate({  
  406.        errorPlacement: function(error, element) {  
  407.          error.appendTo( element.parent("td").next("td") );  
  408.        },  
  409.        debug:true  
  410.      })  
  411.   });  
  412.     
  413. // --></mce:script>  
  414.     
  415. </head>  
  416. <body>  
  417.   <form id="myform" action="/login" method="post">  
  418.     <table>  
  419.         <tr>  
  420.             <td><label>Firstname</label>  
  421.             <td><input name="fname" class="required" value="Pete" /></td>  
  422.             <td></td>  
  423.         </tr>  
  424.         <tr>  
  425.             <td><label>Lastname</label></td>  
  426.             <td><input name="lname" title="Your lastname, please!" class="required" /></td>  
  427.             <td></td>  
  428.         </tr>  
  429.         <tr>  
  430.             <td></td><td><input type="submit" value="Submit"/></td><td></td>  
  431.     </table>  
  432. </form>  
  433. </body>  
  434. </html>  
  435. success String , Callback     
  436. 成功时的class.If specified, the error label is displayed to show a valid element. If a String is given, its added as a class to the label. If a Function is given, its called with the label (as a jQuery object) as its only argument. That can be used to add a text like "ok!".  
  437. 添加"valid" 到验证验证元素, 在CSS中定义的样式  
  438. $("#myform").validate({  
  439.     success: "valid",  
  440.     submitHandler: function() { alert("Submitted!") }  
  441. })  
  442. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  443. <html>  
  444. <head>  
  445.   <mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>  
  446.   <mce:script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" mce_src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></mce:script>  
  447.   <mce:script type="text/javascript"><!--  
  448.   $(document).ready(function(){  
  449.     $("#myform").validate({  
  450.     success: "valid",  
  451.     submitHandler: function() { alert("Submitted!") }  
  452.      })  
  453.   });  
  454.     
  455. // --></mce:script>  
  456.   <mce:style><!--  
  457. label.valid {  
  458.     background: url('http://dev.jquery.com/view/trunk/plugins/validate/demo/images/checked.gif') no-repeat;  
  459.     height:16px;  
  460.     width:16px;  
  461.     display: block;  
  462.     position: absolute;  
  463.     top: 4px;  
  464.     left: 152px;  
  465. }  
  466. --></mce:style><style mce_bogus="1">label.valid {  
  467.     background: url('http://dev.jquery.com/view/trunk/plugins/validate/demo/images/checked.gif') no-repeat;  
  468.     height:16px;  
  469.     width:16px;  
  470.     display: block;  
  471.     position: absolute;  
  472.     top: 4px;  
  473.     left: 152px;  
  474. }</style>  
  475. </head>  
  476. <body>  
  477.     
  478. <form id="myform">  
  479.   <input type="text" name="email" class="required" />  
  480.   <br/>  
  481.   <input type="submit" value="Submit" />  
  482. </form>  
  483. </body>  
  484. </html>  
  485. 添加"valid" 到验证验证元素, 在CSS中定义的样式,并加入“ok”的文字  
  486. $("#myform").validate({  
  487.    success: function(label) {  
  488.      label.addClass("valid").text("Ok!")  
  489.    },  
  490.    submitHandler: function() { alert("Submitted!") }  
  491. })  
  492. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  493. <html>  
  494. <head>  
  495.   <mce:script src="http://code.jquery.com/jquery-latest.js" mce_src="http://code.jquery.com/jquery-latest.js"></mce:script>  
  496.   <mce:script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" mce_src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></mce:script>  
  497.   <mce:script type="text/javascript"><!--  
  498.   $(document).ready(function(){  
  499.         $("#myform").validate({  
  500.     success: function(label) {  
  501.             label.addClass("valid").text("Ok!")  
  502.         },  
  503.         submitHandler: function() { alert("Submitted!") }  
  504.         })  
  505.    });  
  506.     
  507. // --></mce:script>  
  508.   <mce:style><!--  
  509. label.valid {  
  510.     background: url('http://dev.jquery.com/view/trunk/plugins/validate/demo/images/checked.gif') no-repeat;  
  511.     height:16px;  
  512.     width:16px;  
  513.     display: block;  
  514.     position: absolute;  
  515.     top: 4px;  
  516.     left: 152px;  
  517.     padding-left: 18px;  
  518. }  
  519. --></mce:style><style mce_bogus="1">label.valid {  
  520.     background: url('http://dev.jquery.com/view/trunk/plugins/validate/demo/images/checked.gif') no-repeat;  
  521.     height:16px;  
  522.     width:16px;  
  523.     display: block;  
  524.     position: absolute;  
  525.     top: 4px;  
  526.     left: 152px;  
  527.     padding-left: 18px;  
  528. }</style>  
  529. </head>  
  530. <body>  
  531.     
  532. <form id="myform">  
  533.   <input type="text" name="email" class="required" />  
  534.   <br/>  
  535.   <input type="submit" value="Submit" />  
  536. </form>  
  537. </body>  
  538. </html>  
  539. highlight   Callback    Default: Adds errorClass (see the option) to the Element  
  540. 高亮显示错误信息。 或者说重写出错时的出错元素的显示。Override to decide which fields and how to highlight.  
  541. Code  
  542. Highlights an invalid element by fading it out and in again.  
  543. $(".selector").validate({  
  544.   highlight: function(element, errorClass) {  
  545.      $(element).fadeOut(function() {  
  546.        $(element).fadeIn()  
  547.      })  
  548.   }  
  549. })  
  550. Code  
  551. Adds the error class to both the invalid element and it's label  
  552. $(".selector").validate({  
  553.   highlight: function(element, errorClass) {  
  554.      $(element).addClass(errorClass);  
  555.      $(element.form).find("label[for=" + element.id + "]").addClass(errorClass);  
  556.   },  
  557.   unhighlight: function(element, errorClass) {  
  558.      $(element).removeClass(errorClass);  
  559.      $(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);  
  560.   }  
  561. });  
  562. unhighlight Callback    Default: 默认是去掉error类  
  563. Called to revert changes made by option highlight, same arguments as highlight.  
  564.    
  565.    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值