为什么 backbone view.el 是 'body' 一切正常,但当 view.el 是 '#container' 时就坏了?

Why the backbone view.el is 'body' everything is ok but be broken when view.el is '#container'?

我是 backbone 的新手。有a link for my code.

$(function (){
  var test = {};
    test.View = Backbone.View.extend({
        el: 'body',
        initialize: function (){
            this.input = $('#new-todo');
        },
        events: {
            'keyup #new-todo': 'check'
        },
        check: function (){
      console.log('!');
            $('#test').html(this.input.val());
        }
    });
    test.view = new test.View();
});

我找到了 a similar question 但仍然很困惑 it.When 我设置了 el:'#container' keyup 事件不起作用。

我想知道,View.el是什么东西,它的作用是什么? el: 'body'el: '#container'.

有什么不同

Backbone 期望视图仅处理其特定 DOM 元素(el)内的事件。你的 #new-todo#container

外面

I want to know, what is it the View.el, what's is that its function? What's the different from el: 'body' and el: '#container'.

el 是视图一直引用的元素。事件附加到此 el 元素内的元素。

这样想:视图只引用el元素。