This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i = 0; i < divs.length; i++) { | |
divs[i].addEventListener("click", function() { | |
alert("divs #" + i + " was clicked."); | |
}, false); | |
} | |
//这里的i被closure了,每次循环会被更新,而不是当时的值 |