当我点击一个继续按钮时,一些文本框应该显示在一个div中,但它没有发生。这是我的代码。Backbone.js事件不起作用
HTML文件:
<button class="btn btn-success pull-right" id="3continue"
type="button">
我的JavaScript文件:
events:{
'click button#3continue': 'displayCoupon'
},
initialize: function(){
var self=this;
_.bindAll(this,'render','addProductDetails','displayCoupon');
this.collection = new List();
this.addProductDetails();
},
displayCoupon: function(){
//e.preventDefault();
console.log("in displayCoupon");
$('#couponcheck').empty();
$('#couponcheck').append('<div class="col-xs-8"><input type="text" class="form-control" id="enterCoupon"></div>');
$('#couponcheck').append('<div class="col-xs-8"><button type="button" class="btn btn-success btn-sm" id="couponbutton">Apply</button></div>');
},
只是一个提示:你不需要“displayCoupon”绑定bindAll ,因为你没有在这个函数中使用'this'。即使在你使用它的情况下,你也不需要绑定它,因为使用'events'哈希,这个'范围不会被改变。 – MiguelSR
在你的视图的'el'里面是'
@ muistooshort没有它的内部视图的el –