开发者

jQuery Validation rule inner HTML

开发者 https://www.devze.com 2022-12-25 16:59 出处:网络
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.

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");
            });

    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消