G0574's Archiver

弯月圆刀 发表于 2008-8-17 20:08

Using the onDOMReady Method

onDOMReady lets you define a function that will execute as soon as the DOM is in a usable state. The DOM is is not deemed "usable" until it is structurally complete; a number of bugs, primarily in IE, can lead to the browser crashing or failing to load the page successfully if scripts attempt to insert information into the DOM prior to the DOM being in a complete state.

DOM readiness is achieved before images have finished loading, however, so onDOMReady is often an excellent alternative to using the window object's load event.

onDOMReady 使你的函数在DOM进入可用状态时得以执行。如果整个html dom的结构没有完整下载,就不认为进入可用状态。如果在dom没有完成时,javascript就尝试插入内容会导致浏览器崩溃或者下载失败,这是浏览器(特别是ie)中的一些bug造成的。

所以尽量使用onDOMReady而不是浏览器window对象的load事件。

弯月圆刀 发表于 2008-8-17 20:24

As with addListener, onAvailable, and onContentReady, you can pass a data object and adjust the scope YAHOO.util.Event.onDOMReady(init, data, scope);   

你同样可以传送额外的数据和执行环境给onDOMReady,当然还有对应得变形。YAHOO.util.Event.onDOMReady(init, object,true);这样object就成为scope。

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.