点击事件不火

时间:2015-09-22 19:57:42

标签: javascript jquery backbone.js

我试图在BackBone上触发click事件,但是没有得到任何事件, 看起来我确实选择器是正确的,但仍然无法让它工作,thnx寻求帮助! 我的代码是:

  events: {
      "click #search_button": "doSearch"
    },
    doSearch: function (event) {
      // Button clicked, you can access the element that was clicked with event.currentTarget
      alert("Search for " + $("#search_input").val());
    }
  });

  var search_view = new SearchView({el: $("#search_container")});
  search_view.delegateEvents();

模板:

<div class="jumbotron" id="search_template">
  <div class="container">
    <div class="row">
      <div class="col-lg-6">
        <div class="input-group">
          <input type="text" class="form-control" placeholder="Search for..." id="search_input">
  <span class="input-group-btn">
    <button class="btn btn-default" id="search_button" type="button">Go!</button>
  </span>
        </div><!-- /input-group -->
      </div><!-- /.col-lg-6 -->
    </div><!-- /.row -->

  </div>
</div>
<div id="search_container"></div>

0 个答案:

没有答案