我正在使用引导程序 3 和 4,并且希望在用户单击页面上的其他任何位置时关闭所有弹出窗口。我使用https://stackoverflow.com/a/21007629/166231(和第三条评论)作为实施解决方案的指南。
const hideVisiblePopover = function(): void {
const visiblePopover = KatApp[ "visiblePopover" ];
// Just in case the tooltip hasn't been configured
if ( visiblePopover === undefined || $(visiblePopover).data("bs.popover") === undefined ) return;
// Call this first b/c popover 'hide' event sets visiblePopover = undefined
if ( that.bootstrapVersion == 3 ) {
$(visiblePopover).data("bs.popover").inState.click = false
}
$(visiblePopover).popover("hide");
};
我在div所有标记的容器上设置的事件处理程序是:
application.element
.on("show.bs.popover.RBLe", function() { hideVisiblePopover(); })
.on("shown.bs.popover.RBLe", function( e ) {
KatApp[ "visiblePopover"] = e.target;
})
.on("hide.bs.popover.RBLe", function() {
KatApp[ "visiblePopover"] = undefined;
});
但是,使用 bootstrap 5,我尝试bs.popover使用这一行:
$(visiblePopover).data("bs.popover")
返回未定义。现在有不同的地方可以寻找这个吗?