如果我在元素上使用工具提示并弹出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')) {
}
});
答案 0 :(得分:1)
由于它使用jQuery,我相信事件所代表的当前元素只是:
this
或者,
$(this) // to do jQuery operations on it
如果您想检查它是否可见:
if ($(this).is(":visible")) { ... }