简体   繁体   English

为什么点击事件没有传播?

[英]Why click event is not propagating?

Attached a Header with a (kinda) close button (in red) moc-up. 附加了带有(关闭)(红色)关闭按钮(红色)的标题。 When I click on the close button (the area that overlaps with a header) - nothing happens. 当我单击关闭按钮(与标题重叠的区域)时,没有任何反应。 Can you please advice on the correct solution regarding the subject? 您能否就该主题的正确解决方案提出建议?

HTML: HTML:

<div id="my_body" style="background:rgba(0, 0, 0, 0.6);padding:10px;"> 
    <div id="cls_btn" style="position:absolute;left:0px;top:0px;height:50px;width:50px;background-color:red;">  </div>
    <div id="my_header" style="position:relative;padding:14px 26px 26px">  </div> 
    <div id="pic_area" style="border:2px solid #b3b3b3;margin-top:10px">
        <img id="pic" src="http://never.mind.which.pic.com" >
    </div>
</div>

JS: JS:

$("#cls_btn").bind("click", function() {
    alert("clicked!");

    return true;
});

JSFiddle: http://jsfiddle.net/JuGx9/ JSFiddle: http : //jsfiddle.net/JuGx9/

Thanks! 谢谢!

This element ( <div id="my_header" style="position:relative;padding:14px 26px 26px"> </div> ) seems to be occupying the same space and is taking the click event, rather than the #cls_btn div. 该元素( <div id="my_header" style="position:relative;padding:14px 26px 26px"> </div> )似乎占据了相同的空间,并且正在接受click事件,而不是#cls_btn div。 Applying a z-index CSS property with a value of 999 fixes the issue. 应用值为999z-index CSS属性可解决此问题。

Working DEMO 工作演示

Your 'my_header' cover it. 您的“ my_header”将其覆盖。 change the rows to: 将行更改为:

<div id="my_header" style="position:relative;padding:14px 26px 26px">  </div> 
<div id="cls_btn" style="position:absolute;left:0px;top:0px;height:50px;width:50px;background-color:red;">  </div>

The "my_header" div is overlapping the "cls_btn" div. “ my_header” div与“ cls_btn” div重叠。 Look at this: http://jsfiddle.net/JuGx9/13/ 看这个: http : //jsfiddle.net/JuGx9/13/

To solve this without the z-index property change the order of the divs... 要解决此问题而无需更改z-index属性,请更改div的顺序...

http://jsfiddle.net/JuGx9/15/ http://jsfiddle.net/JuGx9/15/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM