Created
August 19, 2013 01:34
-
-
Save callblueday/6265101 to your computer and use it in GitHub Desktop.
return false is better because it prevents the default behavior of the event and also prevents the page from bubbling up. Note that this is only correct in jQuery event handlers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//使用return false来禁用 form的默认submit事件。 | |
<form method="POST" action="" id="search-form"> | |
<input type="text" name="keywords" /> | |
<input type="submit" value="Search" id="sButton" onclick="loadXMLDoc('file.xml')" /> | |
</form> | |
<script> | |
window.onload = function() { | |
document.getElementById("search-form").onsubmit = function() { | |
loadXMLDoc('file.xml'); | |
return false; | |
}; | |
}; | |
</script> |
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
});
用jqeury也可以这么干
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return false is better because it prevents the default behavior of the event and also prevents the page from bubbling up. Note that this is only correct in jQuery event handlers.