流星事件处理程序抑制问题

时间:2013-03-13 13:59:49

标签: javascript meteor

这是我的按钮点击处理程序:

Template.kanjifinder.events({
  'click input.btnOK': function () {
    console.log("click");
        SetCharacters();
      }
});

但是在我为我的文本输入添加下面的事件处理程序之后,上面的按钮点击代码已停止工作。

Template.kanjifinder.events = ({
'keydown input.txtQuery': function (evt) {
  if (evt.which === 13) {
     SetCharacters();
  }
 }
});

如何让keydown事件处理程序和按钮单击事件处理程序都工作?

1 个答案:

答案 0 :(得分:3)

请勿使用=

Template.kanjifinder.events({
'keydown input.txtQuery': function (evt) {
  if (evt.which === 13) {
     SetCharacters();
  }
 }
});

此外,您可以将两者结合使用:

Template.kanjifinder.events({
    'click input.btnOK': function () {
        console.log("click");
        SetCharacters();
    },
    'keydown input.txtQuery': function (evt) {
        if (evt.which === 13) {
            SetCharacters();
        }
    }
});
相关问题