委托的点击事件不会触发后代
Delegated click event not firing on descendants
我有一个 <select>
视图,它有一个方法,每当 click
事件发生在它上面或 <option>
.
时我想调用它
视图如下所示:
mySelect = Backbone.view.extend({
el: '.my-select',
events: {
'click': 'isSelected'
},
isSelected: function(e) {
console.log(e.currentTarget.tagName);
}
});
目前,isSelected()
仅在我单击 select
本身而不是 options
时触发。
我试过 'click option'
、'click *'
和 'click .my-select > option'
。
我错过了什么?
我想做的是不可能的,原因与 Backbone 完全无关!问题是在大多数浏览器中 mouse/keyboard 事件不会在 options
.
上触发
来自 MDN:
Historically, Firefox has allowed keyboard and mouse events to bubble up from the element to the parent element. This doesn't happen in Chrome, however, although this behavior is inconsistent across many browsers.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
让我找到 MDN 的 SO 答案:
onclick on option tag not working on IE and chrome
我有一个 <select>
视图,它有一个方法,每当 click
事件发生在它上面或 <option>
.
视图如下所示:
mySelect = Backbone.view.extend({
el: '.my-select',
events: {
'click': 'isSelected'
},
isSelected: function(e) {
console.log(e.currentTarget.tagName);
}
});
目前,isSelected()
仅在我单击 select
本身而不是 options
时触发。
我试过 'click option'
、'click *'
和 'click .my-select > option'
。
我错过了什么?
我想做的是不可能的,原因与 Backbone 完全无关!问题是在大多数浏览器中 mouse/keyboard 事件不会在 options
.
来自 MDN:
Historically, Firefox has allowed keyboard and mouse events to bubble up from the element to the parent element. This doesn't happen in Chrome, however, although this behavior is inconsistent across many browsers.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
让我找到 MDN 的 SO 答案: onclick on option tag not working on IE and chrome