Using the Metadata method
This requires the use of the Jquery.metadata.js plugin to work, specifying validation rules by defining special properties in the form item
But I found that the latest Jquery.validate 1.11 has no built-in metadata support, so it needs to be modified
Search for $.validator.classrules (element) in the Jquery.validate.js file and add the following line before it: $.validator.metadatarules (Element), Then search staticrules:, add the following code in front of it, add metadata support: Metadatarules:function (Element) { if (!$.metadata) return {}; var meta = $.data (element.form, ' Validator '). Settings.meta; Return meta? $ (Element). metadata () [meta]: $ (Element). metadata (); }, |
Here, the transformation is complete, to use metadata, the page uses the following methods (omitting other code):
<script src= "Lib/jquery.js" type= "Text/javascript" ></script> <script src= "Lib/jquery.metadata.js" type= "Text/javascript" ></script> <script src= "Lib/jquery.validate.js" type= "Text/javascript" ></script> <form> <input name= "User" class= "{required:true,minlength:3}"/> </form> |
However, the default class is used to define the CSS style class name, which is used as a validation rule to create too much inconvenience to the style maintenance, there are two ways to solve the problem:
A. Modifying jquery.metadata.js directly, type modified to attr, name modified to validate, indicating the validation rule obtained from the Validate property of the form item
B. Call $.metadata.settype (' attr ', ' Validate ') in the page header to obtain the validation rule from the Validate property of the form item
-----Excerpt: http://www.55dream.cn/code/javascript/466.html
jquery.validata1.11 How to support metadata