日期:2014-05-16  浏览次数:20391 次

这种情况应该怎么做呢
if(oTarget!=oDiv   &&   oTarget.parentNode!=oDiv   &&   oTarget.parentNode.parentNode!=oDiv)   Hide();

想要的效果就是只要不是点击oDiv或内部的元素就Hide()
有更好的方法吗
这样多几个的话不成串烧了

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<script language= "javascript ">
var clkarea = false;
window.onload=function(){
document.getElementById( "divTest ").onclick = function(){ alert( "divclick "); clkarea = true;};
document.onclick=function(){ alert( "documentclick "); if(!clkarea) document.getElementById( "divTest ").style.display = "none "; clkarea = false; };
}
</script>
</head>

<body>
<div id= "divTest " style= "position:absolute; width:200px; height:200px; border:1px solid #0000FF; top:100px; left:100px; background-color:#FFFFEE "> 此处显示新 Div 标签的内容 </div>
</body>
</html>