`
yeruowei
  • 浏览: 24385 次
  • 性别: Icon_minigender_2
  • 来自: 西安
社区版块
存档分类
最新评论

javascript 阻止事件冒泡

    博客分类:
  • Web
 
阅读更多

event.stopPropagation() 阻止事件冒泡

event.preventDefault() 阻止事件的默认动作

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<a href="http://jquery.com">default click action is prevented</a>
<div id="log"></div>

<script>
$("a").click(function(event) {
  event.preventDefault();
  $('<div/>')
    .append('default ' + event.type + ' prevented')
    .appendTo('#log');
});
</script>

</body>
</html>
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics