preventDefault

防止违约

jquery preventDefault()方法 语法

作用:preventDefault() 方法阻止元素发生默认的行为(例如,当点击提交按钮时阻止对表单的提交)。

语法:event.preventDefault()

参数:

参数描述
event    必需。规定阻止哪个事件的默认动作。这个 event 参数来自事件绑定函数。

jquery preventDefault()方法 示例

<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>
运行实例 »

点击 "运行实例" 按钮查看在线实例