var elems = document.getElementsByTagName('a'); for (var i = 0; i < elems.length; i++) { (function (lockedInIndex) { elems[i].addEventListener('click', function (e) { e.preventDefault(); alert('I am link #' + lockedInIndex); }, 'false'); })(i); }
var elems = document.getElementsByTagName('a'); for (var i = 0; i < elems.length; i++) { elems[i].addEventListener('click', (function (lockedInIndex) { return function (e) { e.preventDefault(); alert('I am link #' + lockedInIndex); }; })(i), 'false'); }
var container = document.querySelector("body"), imgEle = null, length = 0, i = 0; length = this.imgList.length; for (; i < length; i++) { imgEle = this.imgList[i]; imgEle.style.cursor = "pointer"; imgEle.index = (function(num){ alert(num); return num; })(i); imgEle.addEventListener("click", function(){ CNLive.Pic.showFullPic(this); CNLive.Pic.controlBigPic(); }, false); }