ITeye博客

javascript 阻止事件冒泡

yeruowei · 2012-02-10 15:54 · Web · Web前端 · Markdown

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>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。