[問題] 請教jQuery迴圈的問題 !
各位先進好
小弟目前有一小段程式有問題
對jQuery 還不是很熟 ,還請大家多多幫忙 !
for(var i=1;i<best.length;i++){
if(i<10){
document.write("<td id=zone0-"+ i + " width=60 align='center'>0" + i + "</td>");
}else{
document.write("<td id=zone0-"+ i + " width=60 align='center'>" + i + "</td>");
}
if((i%10)==0)document.write("</tr><tr>");
$("td#zone0-"+i).click(function(){
if($(this).css("background-color")=='red'){
$(this).css("background-color","white");
zoneInput[0]--;
best[i]--;
}else{
if(zoneInput[0]>=max){
alert('Over Max');
}else{
$(this).css("background-color","red");
zoneInput[0]++;
best[i]++;
}
}
});
}
我想做的就是在一表格內點任一數字
然後該數字就會做加總
但在 .click(function 裡,迴圈的 i 值都是固定 為 81 (best.length=80)
這是為什麼咧 ?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.248.130.139
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):