您现在的位置是:首页 > 电脑技术查询 > web开发

这里的变量如何表示

编辑:chaxungu时间:2022-10-02 23:22:25分类:web开发

这里的变量怎么表示?
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+ ')} ');
}