如何确定Twitter引导组件事件的来源

How do I determine the source of a Twitter Bootstrap component event?

本文关键字:事件 组件 何确定 Twitter      更新时间:2023-09-26

如果我在一个元素上使用工具提示和popover Twitter Bootstrap Javascript组件,我如何确定哪个组件触发了"显示"事件?

例如:

$("#button").tooltip();
$("#button").popover();
$("#button").on("shown", function(event) {
    // I need to do some (flash) stuff that's specific to the popover content,
    // the shown event is fired for both the tooltip and popover but doesn't 
    // appear to include any useful information about the context of the event.
    // How do I determine if the popover component fired the event? The event.target
    // is useless because it points to #button.
    // The best I've come up with is to check if the element I'm interested in 
    // is visible but I'm assuming this will have issues if the popover component
    // is animated...
    if ($(".popover .thingy").is(':visible')) {
    }
});

由于它使用jQuery,我相信事件表示的当前元素只是:

this

或者,

$(this) // to do jQuery operations on it

如果你想检查它是否可见:

if ($(this).is(":visible")) { ... }