您的位置:首页 > 其它

弹出DIV,点击其它区域让DIV关闭

2010-01-11 15:32 363 查看
在使用div模拟commbox时,一直无法实现“点击其它区域让DIV关闭”,在网上搜到的内容如下:感谢原作者

<html>
<mce:style type=text/css><!--
div {
position: absolute;
z-index: 1;
background: #f00;
top: 100px;
width: 100px;
height: 100px;
}
--></mce:style><style type=text/css mce_bogus="1">div {
position: absolute;
z-index: 1;
background: #f00;
top: 100px;
width: 100px;
height: 100px;
}</style>
<body>
<input type=button value="add layer" onclick=addLayer()>
</body>
</html>
<mce:script type=text/javascript><!--
var bOnWin;

function addLayer() {
var c = document.createElement('div');
c.id = 'oTestLayer';
c.style.left = Math.random()*500 + 'px';
c.onmouseover = function() {bOnWin = 1;}
c.onmouseout = function() {bOnWin = null;}
document.body.appendChild(c);
}
document.documentElement.onmousedown= function() {
var c = document.getElementById('oTestLayer');
if (!bOnWin && c)
document.body.removeChild(c);
}
// --></mce:script>


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  div function button layer null c