[英]Backbone.js events not working
When I click a continue button, some text box should shown in a div, but it's not happening. 当我单击继续按钮时,一些文本框应显示在div中,但没有发生。 Here is my code. 这是我的代码。
html file : html文件:
<button class="btn btn-success pull-right" id="3continue"
type="button">
my javascript file : 我的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>');
},
Please try this: 请尝试以下方法:
Html: HTML:
<button class="btn btn-success pull-right" id="clickMe"
type="button">
Javascript: Javascript:
events:{
'click #clickMe': '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>');
},
In your code you have written 在您的代码中,您已经编写了
events:{
'click button#3continue': 'displayCoupon'
},
try replacing above code with code given below: 尝试用下面给出的代码替换上面的代码:
events:{
'click #3continue': 'displayCoupon'
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.