Home > Web Front-end > JS Tutorial > body text

How to use return false in JavaScript

怪我咯
Release: 2017-07-16 10:47:59
Original
1667 people have browsed it

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);

}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!