2014-11-24 44 views
0

我目前正在一籃子,但似乎無法得到clickHandler函數工作。當我按下按鈕時,它總是會返回「data-id」4.任何建議?這裏有一段代碼和一個js小提琴。籃子onclick處理器

basket.clickHandler = function(){ 
    var targets = document.getElementsByClassName("addButton"); 
    for(var i = 0; i < targets.length; i++) { 
     var target = targets[i]; 
     target.onclick = function() { 
      var shopId = target.getAttribute("data-id"); 
      var item = shop.items[shopId]; 

      basket.add(item); 
     }; 
    }; 
}; 

http://jsfiddle.net/g1L5mwk4/

回答