0

纯 jQuery 版本:

$('select#register-type').live('change', function () {
  console.log($(this).val());
});

主干视图委托事件版本:

App.Views.register = new (Backbone.View.extend({
  tagName: 'section',
  id: 'content',

  template: _.template($('script.register').html()),

  render: function () {
    this.$el.html(this.template);
    return this;
  },

  events: {
    'change select#register-type': 'type'
  },

  type: function (event) {
    // i want to console.log the current option selected... 
  }
}));

我怎样才能做到这一点?看来我不能像 jquery 版本那样使用 $(this) ,这被称为注册视图对象......

4

1 回答 1

1

利用event.target

 type: function (event) {
    $(event.target).find('option:selected').val();

      **OR**

     $(event.target).val();
 }
于 2013-01-22T18:28:38.917 回答