日期:2014-05-16  浏览次数:20386 次

这里的变量怎么表示?
for(var   i=0;i <8;i++){
row1   =   tb.insertRow(0);
cell1   =   row1.insertCell();
cell1.onmouseover=function(){alert(i)};
}

上面是一段给表格增加行的代码,我的本意是当鼠标移动到不同的行时alert出相应的数值来,可是我用上面的代码alert出的总是7,请问该怎么改呢?

------解决方案--------------------
for(var i=0;i <8;i++){
row1 = tb.insertRow(0);
cell1 = row1.insertCell();
eval( 'cell1.onmouseover=function(){alert( '+i+ ')} ');
}