IE背景为transparent(透明)时出现不触发事件的bug
[ 2008-03-20 17:47:25 | 作者: Rank ]
Close Advertisement
不知道算不算是bug了...总之,做个记录,为以后有个参考
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Rank's HTML document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="ImageToolbar" content="no" />
<style type="text/css" title="default" media="screen">
/*<![CDATA[*/
* { font:0.9em Arail; }
.x { padding:10px; border:5px solid #000;width:100px;height:100px;position:absolute; }
/*]]>*/
</style>
</head>
<body>
<div class="x" style="left:200px;top:13px;position:absolute;" onclick='alert("终于点中了...")'>测试一: 不点文字, 点击空白的地方IE7以下不会触发事件</div>
<div class="x" style="background:#eee;left:400px;top:13px;" onclick="alert('加入背景色,可以更正这个bug..');">测试二: 你现在可以点击这个div的任何地方都可以触发事件</div>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Rank's HTML document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="ImageToolbar" content="no" />
<style type="text/css" title="default" media="screen">
/*<![CDATA[*/
* { font:0.9em Arail; }
.x { padding:10px; border:5px solid #000;width:100px;height:100px;position:absolute; }
/*]]>*/
</style>
</head>
<body>
<div class="x" style="left:200px;top:13px;position:absolute;" onclick='alert("终于点中了...")'>测试一: 不点文字, 点击空白的地方IE7以下不会触发事件</div>
<div class="x" style="background:#eee;left:400px;top:13px;" onclick="alert('加入背景色,可以更正这个bug..');">测试二: 你现在可以点击这个div的任何地方都可以触发事件</div>
</body>
</html>
如果此代码再在后边加一个div的话,bug又不出现了...有点奇怪.
尝试在div的css中加入background:transparent,也无效果,只有加入一个真正的background才行...
IE的position还真的是比较麻烦
[最后修改由 Rank, 于 2008-08-01 16:39:09]
评论Feed: http://www.never-online.net/blog/feed.asp?q=comment&id=193


搜了一下,貌似有个家伙也遇到一模一样的问题
http://fleegix.org/articles/2007/08/04/ie-background-css-and-onclick-onmousedown
hi,建议以后类似这样的问题发到ts邮件组里,大家可以一起讨论
很巧合的是那个URL的主人做的demo和我的很相像