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: ......或者我甚至能夠嘗試一切後,頁面的底部,但最終的body
或html
標籤,如: 函數
<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