jQuery Validation rule inner HTML
As we know, jquery.validation.js is very powerful.
In common, we shoul开发者_开发百科d define the rule in js first, and then apply to input element or form.
I'd like to declare the rule inner HTML code, then validator to find and apply the rule. just as below:
<input MaxLength="10" id="StrField" class="required" name="StrField" type="text" value="Test" />
I have used to rules: required MaxLength
My question is all the rules in jquery.validation could be wrote in HTML tag using attribute, and where I could get the document?
can the jquery.metadata help for this?
You can use next code that loading all MaxLength attributes into the rules
$(document).ready(function() {
$.each($("input"), function() {
if ($(this).attr("MaxLength").length > 0 )
$("#myinput").rules("add", {
maxlength: $(this).attr("MaxLength");
});
}
});
精彩评论