调用有参函数的传值问题
function updownmouse(value,j)
{
alert(i);//这里输出的i总为500;
}
function gettd()
{
var a=huaban.getElementsByTagName( "td "),i;
for(i=0;i <a.length;i++)
{
a[i].onclick=function(){updownmouse(i);};
}
}
为什么function(){updownmouse(settd,i);}这个传过去的i总是为500,500为i的最大值
而不是a[1]对应1,a[2]对应2...
------解决方案--------------------updownmouse里面没有i这个变量
------解决方案--------------------能不能贴全代码?
------解决方案-------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD>
<BODY>
<input type= 'button ' name= 'C2 ' value = '0 '>
<input type= 'button ' name= 'C2 ' value = '1 '>
<input type= 'button ' name= 'C2 ' value = '2 '>
</BODY>
<script language= "javascript ">
alert( " ")
function gettd()
{
alert( "1 ")
var a=document.getElementsByTagName( "input ");
alert(a.length)
for(var i=0;i <a.length;i++)
{
a[i].onclick=(function (i){return function(){updownmouse(i);}})(i)
}
}
function updownmouse(i)
{
alert(i);//这里输出的i总为500;
}
gettd();
</script>
</HTML>
闭包问题
http://bbs.51js.com/viewthread.php?tid=61767&highlight=%2B%D4%C2%D3%B0