[英]Polymer fire on-tap with enter
I am beginner on Polymer. 我是Polymer的新手。 I think that it is a easy Problem but i could not find out how can i implement this on my application.
我认为这是一个简单的问题,但是我找不到如何在我的应用程序中实现它。
I have a button on HTML like: 我在HTML上有一个按钮,例如:
<paper-button class="button" id="button-wide" raised affirmative on-tap="{{onClick}}">
and in javascript i have function like: 并且在javascript中,我具有以下功能:
Polymer('dialog', {
onClick: function() {
......
......
}}
And i want fire this button with enter key on keyboard. 我想用键盘上的回车键触发该按钮。
Thanks! 谢谢!
Something like this could work: 这样的事情可能会起作用:
Polymer('dialog', {
onClick: function () {
// etc..
},
onKeyDown: function (e) {
if (e.which === 13 || e.keyCode === 13) {
this.onClick();
}
},
attached: function () {
this.onKeyDown = this.onKeyDown.bind(this);
document.addEventListener('keydown', this.onKeyDown);
},
detached: function () {
document.removeEventListener('keydown', this.onKeyDown);
}
});
where attached and detached are lifecycle methods of the element. 附加和分离的位置是元素的生命周期方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.