イベントの meteor 実装または一般的な Javascript イベントに関連するかわからない問題があります。
「変更」イベントにテキストボックスが添付されています。その隣には、「クリック」イベントに関連付けられたボタンがあります。
テキスト ボックスを変更してボタンをクリックすると、クリック イベントが発生しません (変更イベントのみが発生します)。そのため、クリック イベントを発生させるには、ボタンを 2 回クリックする必要があります。
mousedown
Firefox では、クリック イベントの代わりにイベントをボタンにアタッチすると機能します。Chrome では、どちらの方法でも機能しません。
問題を再現する最小限のコード:
JAVASCRIPT: testevent.js
if (Meteor.isClient) {
Session.set("something", "something");
Template.hello.foo = function() {
return Session.get("foo");
};
Template.hello.something = function() {
return Session.get("something");
}
Template.hello.events({
'click .buttonid' : function () {
console.log("click !");
},
'change .textid' : function (e,t) {
console.log("change !");
var bar = e.target.value;
Session.set("foo",bar);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
HTML: testevent.html
<head>
<title>testevent</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<input type="text" class="textid" value="{{foo}}"/>
<input type="button" class="buttonid" value="{{something}}" />
</template>
クラスを id に置き換えるとクリック イベントが発生しますが、同じ id を持つ複数のフィールドがある場合、イベントは 1 つのフィールドでのみ機能します。