This article mainly introduces the usage of return false in JavaScript. In most cases, it is the event processingfunction Returning false can prevent the default event behavior . Friends who need it can refer to
In most cases, returning false for the event processing function can prevent the default event behavior.
For example, by default, clicking an element will jump to the page specified by the href attribute of the element. Return False is equivalent to the terminator, and Return True is equivalent to the executor. The function of return false in js is generally used to cancel the default action. For example, when you click a link, in addition to triggering your onclick event (if you specify it), you also trigger a default event, which is to execute a page jump. So if you want to cancel the default action of the object, you can return false.
Similarly, return false can be applied to form submission. For example, when we usually verify the form, we need to judge whether the information is true and whether the information is missing. If any of the above conditions are met, , then we need to output the prompt information on the client without submitting it to the server for processing. Return flase can show its talents here - -!
For example
if(a!=b){ return fasel; }else{ alert(11); }
The above is the detailed content of How to use return false in JavaScript. For more information, please follow other related articles on the PHP Chinese website!