Variable scope
Πόση ώρα μπορεί να χάσει κανείς μέχρι να βρεί το λάθος στον παρακάτω κώδικα;
function countServices(maxid)
{
var i=0;
for (i=1;i<=maxid;i++)
{
var divid = 'div' + i;
var numSelectedServices = 0;
var element = document.getElementById(divid);
if (element!=null)
{
if (element.checked==1)
numSelectedServices++;
}
}
alert(numSelectedServices);
}
Ευτυχώς όχι πολύ! ;-)











This work is licensed under a