javascript的问题,简单的递归函数
我真的对javascript及其语法不太熟悉,但是我已经研究出了这个函数,并且当我递归调用它时,我不断收到错误。
function loading(id, formid, point)
{
document.getElementById(id).innerHTML='<span class="red">Please wait until this text disappears! Uploading'+point+'</span>';
document.getElementById(formid).submit();
if(point='...')
{point='';}
else
{point+='.';}
setTimeout('loading('+id+', '+formid+', '+point+')',10);
}
我得到的错误是:
Uncaught TypeError: Cannot call method 'submit' of null
所以变量 formid 似乎没有传递给递归调用。有人知道为什么吗?
谢谢!
梅尼
I am really not very familiar with javascript and its syntax, but I have worked out this function,, and I keep getting errors when I call it recursively.
function loading(id, formid, point)
{
document.getElementById(id).innerHTML='<span class="red">Please wait until this text disappears! Uploading'+point+'</span>';
document.getElementById(formid).submit();
if(point='...')
{point='';}
else
{point+='.';}
setTimeout('loading('+id+', '+formid+', '+point+')',10);
}
The error I get is:
Uncaught TypeError: Cannot call method 'submit' of null
So it seems like the variable formid is not passed to the recursiv call. Anyone knows why?
Thanks!
Maenny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您再次将
formid
放入函数中时,您没有用引号将其括起来,因此您传递的是未定义的变量而不是字符串。无论如何,eval 都是邪恶的。不要将字符串传递给
setTimeout
,而是传递函数。When you eval
formid
into the function again, you aren't surrounding it with quotes, so you are passing a undefined variable instead of a string.eval is evil anyway. Don't pass strings to
setTimeout
, pass functions.