[英]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. MDN 事件参考显示加载事件是所需的触发器。 This post explains not to bind to the
document
node, rather to bind to the window
node. 这篇文章解释了不绑定到
document
节点,而是绑定到window
节点。
window.addEventListener('load', function(){ console.log('document ready!'); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.