---
title: "javascript 阻止事件冒泡"
author: "yeruowei"
date: "2012-02-10T15:54:16Z"
tags: []
categories: ["Web前端"]
slug: "javascript"
draft: false
lastmod: "2012-02-10T18:00:18Z"
id: 1402102
url: "https://yeruowei.iteye.com/blog/1402102"
---

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>
```