Look at this:
$('form).submit(function (event) {
$(':input.required').trigger('blur');
var num = $('.warning', this).length;
alert(num);//Focus here!
if (num) {
event.preventDefault();
};
});
if there're 5 required textbox is empty,then when click the submit button[ID:button1], the num is 5.After triggering the 5 textbox, finding 5 errors, and the code run well.
Also the same button[ID:button1]
$('#button1').click(function (event) {
$(':input.required').trigger('blur');
var num = $('.warning', this).length;
alert(num); //Focus here!
if (num) {
event.preventDefault();
};
});
In this example, the num is 0. Seem like the trigger function is not work well or in time.
Can someone tell me why? thank you very much!