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:

ParameterDescription
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="//m.sbmmt.com/">php中文网</a>
<p>preventDefault() 方法将防止上面的链接打开 URL。</p>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance