【发布时间】:2016-08-15 01:01:15
【问题描述】:
我编写了这段代码,以便在单击“内部 div”后,使用“pointer-events: none;”单击转到“外部 div”。在 CSS 中。
$("#outer").click(function(){
alert("outer clicked")
});
$("#inner").click(function(e){
alert("inner clicked")
this.style.display = 'none';
e.stopPropagation();
});
#outer {
width:300px;
height:200px;
border:3px solid;
margin:auto;
background: green;
}
#inner {
pointer-events: none;
position: absolute;
top: 150px;
left: 120px;
width: 100px;
height: 100px;
background: yellow;
border:3px solid;
margin:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="outer">
<div id="inner">inner div</div>
Outer div
</div>
OK,功能完善。但是,如果您单击外部 div 中的任何位置,我需要隐藏内部 div。我尝试使用this.style.display = 'none';,但它不起作用。
【问题讨论】:
-
对 DOM 中的当前选定元素使用 $(this)。 $(this).css("display","none");应该做的伎俩。
标签: javascript jquery html css