【发布时间】:2017-03-27 10:32:49
【问题描述】:
我已尝试使用以下代码来禁止默认右键单击传单弹出窗口:
$('.leaflet-popup-content-wrapper').bind('contextmenu', function(e) { 返回假; });
此技术适用于所有其他类,但不适用于本例。
有什么想法吗?
【问题讨论】:
标签: popup leaflet right-click
我已尝试使用以下代码来禁止默认右键单击传单弹出窗口:
$('.leaflet-popup-content-wrapper').bind('contextmenu', function(e) { 返回假; });
此技术适用于所有其他类,但不适用于本例。
有什么想法吗?
【问题讨论】:
标签: popup leaflet right-click
没有“抑制”事件这样的事情。你可以停止传播一个事件,阻止一个事件的默认动作,但是抑制一个事件不是一回事。
请阅读:
http://leafletjs.com/reference-1.0.3.html#domevent-stoppropagation
http://leafletjs.com/reference-1.0.3.html#domevent-preventdefault
http://leafletjs.com/reference-1.0.3.html#domevent-stop
https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation
https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
event.preventDefault() vs. return false
您想阻止事件冒泡吗?是否要阻止浏览器显示右键菜单?两者都有?
还要注意,jQuery 事件是 not DOM 事件,此外,Leaflet 事件是非 DOM 事件。在某些情况下,停止 jQuery/Leaflet 事件可能不会停止底层 DOM 事件。在这些情况下,使用Vanilla JS 或一些超级简单的包装器作为L.DomEvent.on() 有助于重新获得控制权。
【讨论】: