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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745169193a4614819.html
评论列表(0条)