从键盘上单击ESC时,角度带关闭弹出窗口

时间:2021-11-11 10:49:54

I'm using Angular-strap, auto-close directive close the popover when clicking outside of it, what about ESC button ? how can i close the popover when ESC button clicked from keyboard ?

我正在使用Angular-strap,自动关闭指令关闭popover时点击它外面,ESC按钮怎么样?如何从键盘上单击ESC按钮时关闭弹出窗口?

1 个解决方案

#1


Here's another SO question that's related to your question though it uses a jQuery approach which you may need to integrate into your app:

这是另一个与您的问题相关的SO问题,尽管它使用了一种jQuery方法,您可能需要将其集成到您的应用中:

Close Bootstrap popover on esc keypress

在esc keypress上关闭Bootstrap popover

Here's the demo: Plunker demo

这是演示:Plunker演示

Here's the jQuery approach:

这是jQuery方法:

$(document).keyup(function (event) {
    if (event.which === 27) {
        $('#example').popover('hide');
    }
});

#1


Here's another SO question that's related to your question though it uses a jQuery approach which you may need to integrate into your app:

这是另一个与您的问题相关的SO问题,尽管它使用了一种jQuery方法,您可能需要将其集成到您的应用中:

Close Bootstrap popover on esc keypress

在esc keypress上关闭Bootstrap popover

Here's the demo: Plunker demo

这是演示:Plunker演示

Here's the jQuery approach:

这是jQuery方法:

$(document).keyup(function (event) {
    if (event.which === 27) {
        $('#example').popover('hide');
    }
});