-1
 rules: {
            cmp_name: {
                minlength: 2,
                required: true
            },
            cmp_surname: {
                 minlength: 2,
                 required: true
            }
}

For example I have form with 100 cmp_name input, how to add rules with loop?

I try this:

 rules: {
         for(var i=0; i<=100; i++ ){
          cmp_name+i{
            minlenght: 2;
            required: true         
          },
         }
}

But it's not working solution, maybe are some like my method but working ?

4

1 回答 1

3

Use the add rules

$("form input").each(function() {
    $(this).rules("add", {
        minlength: 2,
        required: true
    }
});
于 2013-08-04T08:32:39.247 回答