admin管理员组文章数量:1220535
I need to remove focus from input text field from user with the ESC key press. I don't know how to do it with text input fields. Below code works perfectly to detect the ESC key is pressed.
// Triggered Listener to detect event raised from DOM.
@HostListener('document:keydown', ['$event']) onKeydownHandler(event:
KeyboardEvent) {
if (event.keyCode === 27) {
return false;
}
}
Anyone can help how to do?? Thanks
I need to remove focus from input text field from user with the ESC key press. I don't know how to do it with text input fields. Below code works perfectly to detect the ESC key is pressed.
// Triggered Listener to detect event raised from DOM.
@HostListener('document:keydown', ['$event']) onKeydownHandler(event:
KeyboardEvent) {
if (event.keyCode === 27) {
return false;
}
}
Anyone can help how to do?? Thanks
Share Improve this question asked May 24, 2018 at 13:11 Vijay Kumar YadavVijay Kumar Yadav 3171 gold badge3 silver badges12 bronze badges1 Answer
Reset to default 16You can call the blur
method of the input field in the handler of the keydown.escape
event:
<input #txtInput (keydown.escape)="txtInput.blur()">
See this stackblitz for a demo.
本文标签: javascriptHow to remove focus from text field when user presses ESC angular 5Stack Overflow
版权声明:本文标题:javascript - How to remove focus from text field when user presses ESC angular 5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739346448a2159184.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论