开发者

JavaScript event handling timing

I got the following problem. Could you please help?

  1. Have an event handler EH1 on onload event of body.
  2. This event handler EH1 adds a new DOM element by calling a helper function HF1.
  3. Then the event handler EH1 changes the value of the new element.
  4. The event handler EH1 then call another helper function HF2 to calculate the output based on the new element.

In IE and Firefox开发者_开发技巧, if an alert is inserted between step 2 and 3. The output would be correct. If no alert is inserted, the output would be incorrect, as if the helper function HF2 in step 4 cannot see the value of the new element.

In Chrome or Opera, the alert does not help.


Perform your actions on DOMReady instead of onload at body.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜