取消事件传递即可<html>
<head>
<title> </title> <script language="javascript"> function show()
{
event.cancelBubble = true;
var div2 = document.getElementById("div2");
div2.style.display = "block";
} function hide()
{
var div2 = document.getElementById("div2");
div2.style.display = "none";
} function begin()
{
var div1 = document.getElementById("div1");
div1.attachEvent("onclick",show);var bb = document.body;
bb.attachEvent("onclick",hide);
}
</script> </head> <body style="margin:0px;" onload="begin();"> <div id="div1" style="width:30px; height:50px; background-color:#999999;"> </div>
<div id="div2" style="position:absolute; top: 100px; width:200px; height:50px; background-color:red; display:none;"> </div> </body>
</html>
<head>
<title> </title> <script language="javascript"> function show()
{
event.cancelBubble = true;
var div2 = document.getElementById("div2");
div2.style.display = "block";
} function hide()
{
var div2 = document.getElementById("div2");
div2.style.display = "none";
} function begin()
{
var div1 = document.getElementById("div1");
div1.attachEvent("onclick",show);var bb = document.body;
bb.attachEvent("onclick",hide);
}
</script> </head> <body style="margin:0px;" onload="begin();"> <div id="div1" style="width:30px; height:50px; background-color:#999999;"> </div>
<div id="div2" style="position:absolute; top: 100px; width:200px; height:50px; background-color:red; display:none;"> </div> </body>
</html>
解决方案 »
- 下拉框控制问题
- eval无法通过google closure compiler的问题
- 关于谷歌浏览器中地址栏的复制问题。
- 请帮我改改test2()函数,在FF下正常,在IE下不正确
- 如何执行?
- 在myeclipse运行程序出现500错误如下,怎么解决?项目为网上书店
- 如何从一个字符串中提取26个字母部分?
- 综合整理之后的PowerDate .方便处理常日公历日期操作.
- select用js怎么循环的 我的老是报错呀!!
- IE 表单 POST 提交的疑问。
- JS中的使用DWR返回List对象,for循环得到记录集是怎么显示出来的,谁能把我的代码解释一下?
- 正宗HTML RPG WebGame发布:神魔对决1-正义的审判,开源下载+在线游戏.
event.cancelBubble = true;
<div onclick="alert('1')"><div onclick="alert("2")">aaaa</div></div>
如在div2中取消冒泡则只会执行alert("2")