2010-06-11 2 views
0

버튼을 클릭하면 한 div가 표시됩니다. 본문을 클릭하면 해당 div가 숨겨집니다.Div 디스플레이 관련

어떻게하면이 기능을 얻을 수 있습니까? 하나의 코드는 다음과 같습니다.

<!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=iso-8859-1" /> 
<title>Untitled Document</title> 
<script language="javascript"> 
function HideSubMenus(e) 
{ 
var targ; 
if (!e) var e = window.event; 
if (e.target) targ = e.target; 
else if (e.srcElement) targ = e.srcElement; 
if (targ.nodeType == 3) // defeat Safari bug 
    targ = targ.parentNode; 
for (var i=0; i!=5; i++) { 
    if (!targ) { 
    break; 
    } else if (targ.className=="divclass") { 
    return; 
    } 
    targ = targ.parentNode; 
} 

if(document.getElementById("showdivid")) 
{ 
    document.getElementById("showdivid").style.display=''; 
} 
} 
</script> 
</head> 

<body onclick="HideSubMenus(event);"> 
<input type="button" name="button" value="Click ME" onclick="document.getElementById('showdivid').style.display='';" /> 
<div id="showdivid" class="divclass" style="display:none;"> 
TeSt DIV 
</div> 
</body> 
</html> 

관련 주권이 도움이

+1

일부 대답을 수락하면 도움을받을 수 있습니다. –

답변

1

희망.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
<script language="javascript"> 
function HideSubMenus(e) 
{ 
var targ; 
if (!e) var e = window.event; 
if (e.target) targ = e.target; 
else if (e.srcElement) targ = e.srcElement; 
if (targ.nodeType == 3) // defeat Safari bug 
    targ = targ.parentNode; 
    if(targ.className==='btn'){ 
    document.getElementById('showdivid').style.display=''; 
    return; 
    }else{ 
    document.getElementById('showdivid').style.display='none'; 
    } 
} 

</script> 
</head> 

<body onclick="HideSubMenus(event);"> 
<input type="button" name="button" class='btn' value="Click ME" /> 
<div id="showdivid" class="divclass" style="display:none;"> 
TeSt DIV 
</div> 
</body> 
</html> 
+0

안녕하세요 괜찮습니다. 고맙습니다. – user71723