我有这段代码,一切正常,我想让所有元素#content1,#content2 ..当点击正文时隐藏。我试着用z-index比格小设定的身体,而它并没有帮助当你点击body时隐藏元素html
$(function() {
$('#div1').click(function() {
$('#content1, #content2, #content3').hide();
$('#content1').show();
/* other code ..*/
});
$('#div2').click(function() {
$('#content1, #content2, #content3').hide();
$('#content2').show();
/* other code ..*/
});
});
html,body{width:100%;height:100%;}
#div1, #div2, #div3{
overflow:hidden;
float:left;
width:40px;
height:40px;
background:red;
margin:0 10px 0 0;
}
#content1, #content2, #content3{
overflow:hidden;
position:absolute;
top:50px;
background-color:#000;
color:#fff;
padding:2px 4px;
}
<!doctype html>
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div1">
<div id="content1" style="display: none;">
text1
</div>
</div>
<div id="div2">
<div id="content2" style="display: none;">
text2
</div>
</div>
<div id="div3">
<div id="content3" style="display: none;">
text3
</div>
</div>
</body>
</html>
你有这里的问题是,如果'div'的内容是隐藏的,那么你就无法点击它,使他们再次可见 –
另外请注意,我改变了你的标题和描述问题。 “关闭”和“禁用”与您的代码使用的隐藏/显示逻辑非常不同。 –