http://www.quirksmode.org/js/events_tradmod.html
这里有点解释:
看这段
No parentheses!
Please note that in the registration of an event handler you do not use parentheses (). The onclick method expects to be assigned an entire function. If you’d do
element.onclick = doSomething();
the function would be executed and its result would be registered to onclick. This is not what we want, we want the function to be executed when the event takes place. In addition the function has usually been written to expect an event and if we’d execute it without any such context it would get terribly confused and produce JavaScript errors.
Instead we copy the function doSomething() to the event handler in its entirety. We do not execute it yet, that should only happen when the event actually takes place.