处理 z-index'd 图层上的点击事件
我正在构建的地图应用程序中有 2 个 z-index 图层.当我单击要放大的图层时遇到问题.单击处理程序位于底层 z-index 图层上,我不希望在单击覆盖图层中的控件时触发它.
I have 2 z-index layers in a map application I'm building. I have a problem when I click on the layers to zoom in. The click handler is on the underlying z-index layer and I don't want it to fire when a control in the overlying layer is clicked.
我遇到的问题是,无论如何都会引发事件,但是当单击顶层上的某些内容时,事件的 originalTarget 属性不是底层中的图像.有没有办法改变这个?
The problem i have is that the event gets raised no matter what but the originalTarget property of the event is not the image in the underlying layer when something on the top layer is clicked. Is there anyway to change this?
推荐答案
叫做事件冒泡,可以通过event.stopPropagation()
方法来控制(event.cancelBubble()
在 IE 中).您还可以通过从元素上的 onwhatever 属性调用的处理程序返回 true/false 来控制它.这是一个棘手的问题,所以我建议你做一些研究.
It's called event-bubbling, and you can control it with the event.stopPropagation()
method (event.cancelBubble()
in IE). You can also control it by returning true/false from handlers called by onwhatever attributes on elements. It's a tricky subject so I suggest you do some research.
信息:cancelBubble, stopPropagation
相关文章