div标签的Angular 2 keyup.enter

时间:2017-06-26 11:05:12

标签: angular angular2-forms keyboard-events

我需要从选中的div输入键中触发一个功能。我写了下面的代码,但它没有用。

DF.select("_id", "_source.request.user_ip","_source.request.aw", "_type").show(false)

+--------------------+------------+------------------------------------+-----+
|_id                 |user_ip     |aw                                  |_type|
+--------------------+------------+------------------------------------+-----+
|AVzO9dqvoaL5S78GvkQU|111.11.11.12|285d5034-dfd6-44ad-9fb7-ba06a516cdbf|DPAPI|
|AVzO9dq5S78GvkQU    |111.11.11.82|null                                |DPAPI|
+--------------------+------------+------------------------------------+-----+

如何从div输入键触发此功能?

2 个答案:

答案 0 :(得分:2)

看看这个答案。 How to bind keyboard events to div elements?

使用tabindex: The tabindex global attribute is an integer indicating if the element can take input focus (is focusable)

答案 1 :(得分:2)

试试这段代码。这有帮助。 的 HTML

@HostListener('document:keydown', ['$event'])
    handleKeyboardEvent(event: KeyboardEvent): void {
        if (event.keyCode === 13) {
            **// do your code here**
        }
    }

//组件

table1
table1_h

table2
table2_h