admin管理员组文章数量:1415073
I wrote code that should clear form when user open page. It's working in FF but not in IE, any idea why?
window.onload = clearForm()
function clearForm()
{
("load event detected!");
};
I wrote code that should clear form when user open page. It's working in FF but not in IE, any idea why?
window.onload = clearForm()
function clearForm()
{
("load event detected!");
};
Share
Improve this question
edited Jun 26, 2012 at 11:06
Marcel Korpel
21.8k6 gold badges62 silver badges80 bronze badges
asked Jun 26, 2012 at 9:18
Nasan ErtNasan Ert
411 silver badge5 bronze badges
1
- 2 This has to be a duplicate. It has to be. :-) – T.J. Crowder Commented Jun 26, 2012 at 9:22
2 Answers
Reset to default 4This line:
window.onload = clearForm()
calls clearForm
and then assigns its return value to window.onload
, exactly like x = foo();
calls foo
and assigns the result to x
. Remove the parens:
window.onload = clearForm
Separately, I would strongly remend not relying on the horror that is automatic semicolon insertion. Always supply all required semicolons:
window.onload = clearForm;
(Amusingly, you don't need the one at the end of your function clearForm() { ... }
, because that's a function declaration, not a statement. It's harmless, though.)
Change window.onload = clearForm()
to window.onload = clearForm;
otherwise because of ()
you are assigning result of your function to window.onload
本文标签: Javascript windowonload not working in IEStack Overflow
版权声明:本文标题:Javascript window.onload not working in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745169184a2645868.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论