preventDefault
Prevent breach of contract
jquery preventDefault() method syntax
Function: preventDefault() method prevents the element from performing the default behavior (for example, preventing submission of the form when the submit button is clicked).
Syntax: event.preventDefault()
Parameters:
Parameter | Description |
event | Required. Default action that specifies which events are blocked. The event parameter comes from the event binding function. |
jquery preventDefault() method example
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("a").click(function(event){ event.preventDefault(); }); }); </script> </head> <body> <a href="http://www.php.cn/">php中文网</a> <p>preventDefault() 方法将防止上面的链接打开 URL。</p> </body> </html>
Click the "Run instance" button to view the online instance