[英]addeventlistener click only working on first click
一直在嘗試重新創建舊的掌上飛機的“塗料大戰”游戲,無法弄清楚代碼的哪一部分將其弄亂了。 當您單擊+按鈕時嘗試將1加到該值。 這是代碼,謝謝!
init: function(){
this.acid = document.getElementById('acid');
this.acidQty = document.getElementById('acidQty');
this.acidAdd = document.getElementById('acidAdd');
},
// bind the events to the button
bindEvents: function(){
this.acidAdd.addEventListener('click', this.addAcid.bind(this), false);
// $("#acidAdd").on('click', this.addAcid.bind(this));
},
//Get the value
getQty: function(){
this.acidQuantity = $('#acidQty').val();
},
//get current value and add 1
addAcid: function(){
this.getQty();
this.acidQuantity ++;
this.updateQuantity();
},
// update the value on the html
updateQuantity: function(){
this.acidQty.innerText = this.acidQuantity;
},
這是所有代碼的jsbin,以防我錯過了其他東西
沒有看到所有代碼很難說,但我相信以下更改應該起作用。
this.acidQuantity: 1,
bindEvents: function(){
this.acidAdd.addEventListener.addEventListener('click', this.addAcid);
},
addAcid: function(){
this.updateQuantity();
this.acidQuantity ++;
},
updateQuantity: function() {
$('#acidQty').html(app.acidQuantity);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.