Use of return False in JavaScript _javascript tips

Source: Internet
Author: User

In most cases, return false for the event handler to prevent the default event behavior.

For example, by clicking on a <a> element by default, the page jumps to the page specified by the href attribute of the element. Return False is the equivalent of a terminator, and return True is the equivalent of an operator. The function of return false in JS is generally used to cancel the default action. For example, you click a link to trigger a default event in addition to triggering your onclick event (if you specify) to perform a page jump. So if you want to cancel the default action on the object, you can return false.

Similarly, return false can be applied to the submission of a form. For example, we usually in the validation form, to the client to determine whether the information is true, whether the leakage of information, if the above conditions are met, then we need, in the client output prompt information, and will not be submitted to the server processing, Return flase just to be able to work here--!

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.