例如我有:
Job.Views.Response = Backbone.View.extend({
el: '.ra-response-button',
events: {
"click" : "alert"
},
alert: function() {
console.log(this.$el);
};
)};
我有多个按钮(按钮)。 我只想点击按钮就能完成这项工作。我怎么能这样做?
答案 0 :(得分:2)
将el
更改为按钮的父元素,然后执行类似
<div id="buttonWrapper">
<input type="button" id="button1" />
... snip ...
</div>
查看:
Job.Views.Response = Backbone.View.extend({
el: 'buttonWrapper',
events: {
'click #button1': 'eventHandler1',
'click #button2': 'eventHandler2',
... And so on...
}