This example describes the jquery validate plug-in Submithandler commit to a dead loop solution. Share to everyone for your reference, specific as follows:
Dom's submission to the image (Form.submit); and jquery's Submission $ ('). submit (); There is no difference in functionality. But if you use the jquery validate plug-in, the two will be a big difference when submitting. $ ('). submit (); The jquery validate is validated at the time of submission, Submithandler if the $ (') is written. Submit (), cause a dead loop, and Form.submit ();
This problem is a small problem, if you do not pay attention, or write habits, error prone, and error, it is difficult to find. It took me nearly two hours to find out why.
One, simply say Dom to like and jquery to like
Dom to like, you want to use the style of JS to operate, the label on the page. and jquery to the image, you have to use the jquery syntax to operate.
Dom to like to convert to jquery, it is also very simple, add $ () This is OK, and then you can use the syntax of jquery to manipulate the page in the label. I think the most people use is this. Take a look at the example.
$ (' input[name^= "Hour"]). each (function (index) {
this.value=index;//this is dom to image, JS writing
});
$ (' input[name^= "Hour"]). each (function (index) {
$ (this). Val (index);//$ (this) is a jquery-like, jquery notation
});
Two, jquery validate Dead loop procedure
$ ("#product_form"). Validate ({
focusinvalid:false,
submithandler:function (form) {
$ ('. Submit '). Submit ();
}
});
Correct wording,
$ ("#product_form"). Validate ({
focusinvalid:false,
submithandler:function (form) {
form.submit ();
}
});
When a dead loop occurs, the browser will always be loaded until the browser hangs up, and this time, you can add an alert, and you will know that validate has been looping through the verification. Personally, although it is a small problem, but it is difficult to remember.
More about jquery plug-ins interested readers can view the site topics: "jquery common Plug-ins and Usage summary"
I hope this article will help you with the jquery program design.