當DOM完成加載的時候綁定一個要執行的函數。version added: 1.0
jQuery( callback )
callback 當DOM完成加載的時候綁定的函數
允許你綁定一個在DOM文檔載入完成後執行的函數。這個函數的作用如同$(document).ready()一樣,只不過用這個函數時,需要把頁面中所有需要在 DOM 加載完成時執行的$()操作符都包裝到其中來。從技術上來說,這個函數是可鏈接的--但真正以這種方式鏈接的情況並不多。
例子:
Example: Executes the function when the DOM is ready to be used.
$(function(){
// Document is ready
});
Example: Uses both the shortcut for $(document).ready() and the argument to write failsafe jQuery code using the $ alias, without relying on the global alias.
jQuery(function($) {
// Your code using failsafe $ alias here...
});