打开网页的警告框 还是 1.2.3.4.5.6.7 往上跳的~ 赋完ID后,onclick 事件 点出来都是 7,也就是说 都是同一张图片~ 怎么回事? 求解!!
function show() {
var a = new Array();
var i = 1;
for (i = 1; i <= 6; i++) {
a[i] = "file:///E|/html/img/media" + i.toString() + ".jpg";
//file:///E|/html/img/media1.jpg
}
var ima = new Array();
for (i = 1; i <= 6; i++) {
var imgId=i;
var smallside = document.getElementById("smallside");
ima[i] = document.createElement('img');
ima[i].id=imgId;
alert(ima[i].id);
ima[i].src = a[i];
ima[i].style.width="100%";
ima[i].style.height="25%";
smallside.appendChild(ima[i]);
document.getElementById(ima[i].id).onclick=function(){alert(i);showlarge(i-2)};
}
}
function show() {
var a = new Array();
var i = 1;
for (i = 1; i <= 6; i++) {
a[i] = "file:///E|/html/img/media" + i.toString() + ".jpg";
//file:///E|/html/img/media1.jpg
}
var ima = new Array();
for (i = 1; i <= 6; i++) {
var imgId=i;
var smallside = document.getElementById("smallside");
ima[i] = document.createElement('img');
ima[i].id=imgId;
alert(ima[i].id);
ima[i].src = a[i];
ima[i].style.width="100%";
ima[i].style.height="25%";
smallside.appendChild(ima[i]);
document.getElementById(ima[i].id).onclick=function(){alert(i);showlarge(i-2)};
}
}
改成下面试试
document.getElementById(ima[i].id).onclick=function(val){alert(val);showlarge(val-2)(i)};
document.getElementById(ima[i].id).onclick=function(){alert(i);showlarge(i-2)};
})(i);