纯JavaScript等效于jQuery的$ .ready()-页面/ DOM准备就绪时如何调用函数[重复]

问题:

This question already has an answer here: 这个问题已经在这里有了答案: javascript

Okay, this might just be a silly question, though I'm sure there are plenty of other people asking the same question from time to time. 好的,这可能只是一个愚蠢的问题,尽管我敢确定会有不少其余人不时问一样的问题。 Me, I just want to make 100% sure about it either way. 我,我只是想以任何一种方式100%肯定它。 With jQuery we all know the wonderful 有了jQuery,咱们都知道精彩之处 html

$('document').ready(function(){});

However, let's say I want to run a function that is written in standard JavaScript with no library backing it, and that I want to launch a function as soon as the page is ready to handle it. 可是,假设我要运行一个用标准JavaScript编写且没有库支持的函数,而且我想在页面准备好处理后当即启动一个函数。 What's the proper way to approach this? 解决这个问题的正确方法是什么? java

I know I can do: 我知道我能够作: 浏览器

window.onload="myFunction()";

...or I can use the body tag: ...或者我能够使用body标签: app

<body onload="myFunction()">

...or I can even try at the bottom of the page after everything, but the end body or html tag like: ......或者我甚至能够尝试一切后,页面的底部,但最终的bodyhtml标签,如: 函数

<script type="text/javascript">
   myFunction();
</script>

What is a cross-browser(old/new)-compliant method of issuing one or more functions in a manner like jQuery's $.ready() ? 什么是跨浏览器(旧/新)兼容方法,以相似于jQuery的$.ready()的方式发布一个或多个函数? ui


解决方案:

参考一: https://stackoom.com/question/fXHI/纯JavaScript等效于jQuery的-ready-页面-DOM准备就绪时如何调用函数-重复
参考二: https://oldbug.net/q/fXHI/Pure-JavaScript-equivalent-of-jQuery-s-ready-how-to-call-a-function-when-the-page-DOM-is-ready-for-it-duplicate
相关文章
相关标签/搜索