domready
The "domready" event, as it is affectionately known as, is one of the best things since sliced bread. The domready event says "screw you window.load ... I don't have time to wait for you." The ability to execute your JavaScript method on DOM nodes before the page loads helps to make our effects and element modifications that much more seamless. Every JavaScript framework has their own method of domready so I wanted to take the time to list off each one, just in case you (or I) need to work with a framework that's (initially) outside of our comfort zone.
众所周知,“准备就绪”事件是切成薄片以来最好的事情之一。 domready事件显示“为您拧下window.load ...我没有时间等你。” 在页面加载之前在DOM节点上执行JavaScript方法的能力有助于使我们的效果和元素修改更加无缝。 每个JavaScript框架都有自己的domready方法,因此我想抽出时间列出每个方法,以防万一您(或我)需要(最初)需要在我们舒适范围之外的框架工作。
MooTools(FTW) (MooTools (FTW))
window.addEvent('domready',function() {
//do stuff
});
jQuery的 (jQuery)
jQuery(document).ready(function() {
//do stuff
})
Dojo工具包 (Dojo Toolkit)
dojo.addOnLoad(function() {
//do stuff
});
UI (YUI)
YUI().use('*',function(Y) {
Y.on("domready", function() {
//do stuff
}, Y, "The DOMContentLoaded event fired. The DOM is now safe to modify via script.");
});
原型 (Prototype)
document.observe("dom:loaded", function() {
//do stuff
});
煎茶 (Sencha JS)
Ext.onReady(function() {
//do stuff
});
Be sure to let me know if I'm missing a framework -- I'd like this list to become as comprehensive as possible!
如果缺少框架,请务必让我知道-我希望这份清单尽可能全面!
domready