[英]First click handler removes element and second handler doesn't run, how can I run both?
I'm using a jQuery plugin (leaflet.js) that has popups. 我正在使用具有弹出窗口的jQuery插件(leaflet.js)。 I want to do some stuff when the close button is clicked, but since I'm not the one creating the close button, I have to attach a handler with
jQuery.on()
like so: 我想在单击关闭按钮时做一些事情,但是由于我不是创建关闭按钮的人,因此我必须使用
jQuery.on()
附加一个处理程序, jQuery.on()
所示:
$(document).on('click', '.leaflet-popup-close-button', function () {
// do stuff
}
This works for other events (such as mouseover
), but because it's a close button I'm clicking, the element disappears the instant it's clicked, and my handler isn't run. 这适用于其他事件(例如
mouseover
),但是由于它是我单击的关闭按钮,因此元素在单击后即消失,并且我的处理程序未运行。
How can I make my handler ALSO run (I don't want to remove the handler that's already there)? 如何使我的处理程序也运行(我不想删除已经存在的处理程序)?
edit 编辑
I can't use the built-in popupclose
event because that event also fires if the popup is closed some other way. 我无法使用内置的
popupclose
事件,因为如果以其他方式关闭弹出窗口,该事件也会触发。
我对传单不是很熟悉,但是我认为您需要将closeButton
选项设置为false,使用您自己的关闭按钮来编辑弹出窗口的DOM,并在其他任何代码之后使用click事件的回调调用togglePopup
或closePopup
你要。
我建议您侦听leaflet.js中的close事件,并使用该事件来触发您的操作: http ://leafletjs.com/reference.html#popup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.