Jquery cannot submit a solution for a form after returning false in the Submit method.

Source: Internet
Author: User

Today, when doing exercises, use jquery to do the wrong thing at the front desk.

There is a need to prevent users from submitting a form when checking for logic that has errors. Such a demand.

At that time, because do not want to use

<input type= ' Submit ' onsubmit= "return XX ()"/>

This method, so direct code out of such a sentence.
$ ("#提交按钮"). Submit (function () {return false;})
Then, when testing, you can actually implement a block form submission when the user enters the wrong information.

But the problem comes with it. After the user corrects the error. When submitting again, the form is no longer submitted.

In other words, just as with the previous error message, there will be no response from the user point submission.

Later, the internet looked up. Presumably, because when you run that sentence, the browser stops the default event and event bubbling for the specified object.

So, as long as you run that sentence, no matter how you click on that button, the form will not be submitted.

At this point, know the reason, began to solve. However, at this time again fell into another cul-de-sac, then kept thinking, how to make the submit button to restore the initial state. Wasted a lot of time.

In fact, just to make sure that all the logic is correct, call the

$ ("#表单ID"). Submit ()
It's okay.

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.