3

我试图检测用户何时在聊天框中按下返回/输入以发送消息。我如何检测一个paper-input元素?

4

1 回答 1

4

paper-input 继承自,当用户点击 enter/return 或元素失去焦点时core-input会触发一个事件。change如果您不关心失去焦点的情况(例如,只想要用户按 ENTER 的情况),您可以检查document.activeElement

document.querySelector('paper-input').addEventListener('change', function(e) {
  if (document.activeElement == this) {
    console.log('ENTER hit on aper-input');
  }
});

http://jsbin.com/godaqugacecu/1/edit

请参阅http://www.polymer-project.org/docs/elements/core-elements.html#core-input

于 2014-08-29T12:59:47.017 回答