---
title: "给body标签和document.body都添加点击事件后仅Firefox之弹出了两次"
author: "zhouyrt"
date: "2011-04-02T16:56:46Z"
tags: []
categories: ["Web前端"]
slug: "body-document-body-firefox"
draft: false
lastmod: "2011-04-02T16:56:46Z"
id: 985021
url: "https://snandy.iteye.com/blog/985021"
---

这是菜菜刚刚发现的

 

```
<!DOCTYPE html>
<html style="background:red">
  <head>
	<meta charset="utf-8">
	<title>给body标签和document.body都添加点击事件后仅Firefox之弹出了两次</title>
  </head>  
<body onclick="alert(1)" style="background:yellow;">
	<p>HTML BODY</p>
	<script>
	document.body.onclick=function(){
		alert ('body');
	};
	</script>
</body>
</html>
```

 

1，给body标签添加了onclick事件，弹出1

2，给document.body添加了onclick事件，弹出body

点击页面红色区域

IE6/7/8/9/Safari/Chrome/Opera : 不弹任何消息

Firefox : 弹出1

点击页面黄色区域

IE6/7/8/9/Safari/Chrome/Opera : 弹出body

Firefox : 弹出body，再弹1

呃..