简体   繁体   中英

Javascript - How to use addEventListener to trigger on a page's ready state [no jQuery]

对于javascript addeventlistener加载Google的热门搜索是基于jQuery的,因此与我无关。我想要一个干净的参考书,以了解如何将事件最好地绑定到原始javascript中的文档就绪状态。

how to best bind an event to a document's ready state

That would probably be...

document.addEventListener("DOMContentLoaded", function() { });

MDN's Reference for Events show the load event being the desired trigger. This post explains not to bind to the document node, rather to bind to the window node.

window.addEventListener('load', function(){ console.log('document ready!'); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM