0

例如我有:

Job.Views.Response = Backbone.View.extend({
el: '.ra-response-button',
    events: {
      "click" : "alert"
    },

    alert: function() {
       console.log(this.$el);
    }; 
)};

我有多个按钮(按钮)。我希望只有单击按钮才能工作。我怎么能这样做?

4

1 回答 1

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...
   }
于 2013-04-11T07:31:17.293 回答