問題描述
我正在構建的地圖應用程序中有 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
這篇關于處理 z-index'd 圖層上的點擊事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!