JQuery Validate Plugin Submithandler commits a dead loop solution _jquery

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.