我试图在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>