Encountered this problem today:
//pseudocode
for (var i=0; iaddEvent(obj[i], "click", func(i));
}
The result appears The problem was solved. All DOM events were registered when i=n. After checking some information, it was said that this was changed during the loop process, and the registered events were also changed accordingly. I found a solution;
for (var i=0; i< n; i ) {
(function (i){addEvent(obj[i], "click", function (){func(i);});})(i);
}
Use bipack to maintain persistent references to variables, very powerful!
(If you have a better method, please feel free to enlighten me (*^__^*) Heehee...)