名前空間のカスタムイベントがjQueryでどのように動作するはずです。私はthe docから、名前空間付きのカスタムイベントを起動すると、そのイベントに固有のハンドラーしか起動しないという印象を受けました。代わりに、名前空間はほとんど無視されているようです。以下の例とライブコード:http://jsfiddle.net/kZCBw/1/名前空間カスタムイベントトリガー
$(document)
.bind("reset.one", function(){ console.log("reset.one event detected");})
.bind("reset.two", function(){ console.log("reset.two event detected");})
.bind("cheese", function(){ console.log("cheese event detected");});
$("#btn1").click(function(){
console.log("firing reset.one event");
$(this).trigger("reset.one");
});
$("#btn2").click(function(){
console.log("firing reset.two event");
$(this).trigger("reset.two");
});
$("#btn3").click(function(){
console.log("firing reset event");
$(this).trigger("reset");
});
//btn1 click should only trigger handlers bound to "reset.one"
//and yet it triggers anything starting w/ "reset"
私は何が欠けていますか?
ありがとうございます! -matt
サイドノート:jQuery 2.1.4とjQuery 3.0でうまく動作します。 – ViRuSTriNiTy