简体   繁体   English

Javascript-如何使用addEventListener触发页面的就绪状态[没有jQuery]

[英]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.

相关问题 Javascript window.addEventListener() 在调用 jQuery.load() 命令到新的 Z2FEC392304A5FDABBACZ 页面后无法触发 - Javascript window.addEventListener() fails to trigger after calling a jQuery .load() command to a new PHP page 如何在 Javascript 的 addEventListener 中使用 return ? - How to use return in addEventListener in Javascript? 使用jQuery获取PDF加载就绪状态 - Use jQuery to get a PDF load ready state jQuery 等效于 JavaScript 的 addEventListener 方法 - jQuery equivalent of JavaScript's addEventListener method 如何在 JQuery 中只触发一次“就绪”? - How to trigger "ready" only once in JQuery? 如何访问另一个页面的元素以在 javascript 中使用? 请不是 JQuery - How to access another page's elements to use in javascript? Not JQuery please 我可以使用jQuery .trigger()和addEventListener()添加的事件侦听器吗? - Can I use jQuery .trigger() with event listeners added with addEventListener()? JavaScript范围和jquery的$(document).ready - javascript scope and on jquery's $(document).ready 如果Javascript代码块不在HTML文件的末尾,而是使用jQuery的$(document).ready(function(){...}),它会减慢页面显示吗? - If Javascript code block is not at end of HTML file, but is using jQuery's $(document).ready(function() {…}), will it slow down the page display? 如何使用Javascript的addEventListener()来覆盖HTML表单的默认submit()行为 - How to use Javascript's addEventListener() to override an HTML Form's default submit() behavior
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM