简体   繁体   English

第一次单击处理程序会删除元素,而第二个处理程序不会运行,如何同时运行两者?

[英]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事件的回调调用togglePopupclosePopup你要。

我建议您侦听leaflet.js中的close事件,并使用该事件来触发您的操作: http ://leafletjs.com/reference.html#popup

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

相关问题 如何运行元素的click事件处理程序? - How can I run element's click event handler? 切换事件处理程序无法运行 - toggle event handler doesn't run 在运行ugug的ng-click处理程序之前或期间,如何切换加载指示器? - How can I toggle a loading indicator before or during anuglar's ng-click handler is run? 如何获取通过在 forEach 中添加的单击处理程序单击的元素? - How can I get the element that is clicked on with a click handler added in a forEach? 如何使用 CSS 启用/禁用元素的点击处理程序? - How can I enable/disable an element's click handler with CSS? WkWebView 消息处理程序第一次不返回文本框的值,但它在我第二次按下按钮时返回 - WkWebView Message handler doesn't return the value of textbox first time, but it does the second time I press the button 在运行时HTML元素上调用click事件处理程序 - Calling a click event handler on run-time HTML element Wordpress ajax 处理函数不运行(javascript 导致成功) - Wordpress ajax handler function doesn't run (javascript results in success) 删除子元素的onclick处理程序 - onclick handler that removes child element 如何使用jquery在Internet Explorer 10中运行click事件处理程序? - How to run click event handler in Internet Explorer 10 using jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM