In most cases, false is returned 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 equals the Terminator, and return True is the equivalent of the executor.
<a class= "Testreturn" href= "http://www.baidu.com" > Baidu </a>$ (". Testreturn"). On (' click ',function (e) { alert ("test"); return false ; }) // links do not jump
<form action= "form_action.asp" method= "POST" id= "Subform" > <p>first Name: <input type= "Text" Name= "FName"/></p> <p>last Name: <input type= "text" name= "lname"/></p> < Input type= "Submit" value= "Submit"/> </form>function submitaction () { alert (); return false ; } $ ("#subForm"). On ("Submit", submitaction);
The Submitaction method has the action of submitting the form. If you do not add return False, the Submit button will continue to execute its default event after Submitaction executes, and the form will be submitted again. This may be the source of many mistakes.
Indeed, the meaning of return false is not to prevent the event from continuing to propagate to the top-level element, but to block the browser's default handling of events. You can experiment with this: first comment out all the JS script, in the Internet Explorer to try to drag a piece, you will find that the mouse will be a prohibited operation of the style, the picture is forbidden to drag, it is the browser for the MouseMove event provides the default behavior. Return false is to remove this behavior, or the interrupt event that you describe is executed consecutively.
In addition, the statement equivalent to return false is: Window.event.returnValue = False, you can replace the return false with this statement and verify.
Finally, this approach applies only to IE browsers.
JavaScript return False