在这个例子中,我希望只有在点击黑色外部div时才会触发警报,而不是点击内部div中的任何内容时都触发。
目前,当我单击内部按钮时,它会触发警报。
$("#outer").click(function() {
alert("triggered");
});
#outer{
position: absolute;
width: 100%;
height: 100%;
background-color: #000;
display: flex;
justify-content: center;
align-items: center;
}
#inner{
background-color: #fff;
width: 300px;
height: 300px;
text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="outer">
<div id="inner">
<button>inner button</button>
</div>
</div>
我想在内部 div 中不触发警报。我该怎么做?
(由于某种原因,内部按钮在片段中未显示,这是 codepen 链接:https://codepen.io/GuerrillaCoder/pen/Pmvmqx)