addeventlistener只在第一次点击时点击

时间:2016-08-27 23:59:06

标签: javascript addeventlistener

一直试图重新创建旧的掌上飞行员涂鸦战争游戏,无法弄清楚代码的哪一部分搞乱了这一点。单击+按钮时,尝试将值加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

http://jsbin.com/wakoqeduwo/1/edit?html

1 个答案:

答案 0 :(得分:1)

如果没有看到所有代码,很难分辨,但我相信以下更改应该有效。

viewDidLoad(){
   switch step{
   case 0:
       //add this data
   case 1:
       //add this data
   case 2:
       //add this data
   default: break
}
相关问题