當我點擊一個繼續按鈕時,一些文本框應該顯示在一個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 –