I have two forms in a page
<form id="form1">
</form>
<form id="form2">
</form>
in javascript
$('form').validate();
Above only applies validator to form1 not form2. i thought jquery selector applies to all matched elements.
I had to call validate on individual form to apply
Is something wrong with what i am doing/ex开发者_如何学JAVApecting? isn't $('form').validate() should apply to all forms in a page?
While the jQuery function does grab every matching element for the selector, it is up to the plugin to use those elements. It looks like the validate plugin you are using (can't confirm if it is this one) only grabs the first element of the selector to act upon.
By wrapping the validate function with an each, you should be able to get the validate functionality for each form.
$('form').each(function(){
$(this).validate();
});
Try this instead:
$('form').each(function(){
$(this).validate();
});
精彩评论