$(document).ready()的簡短寫法$()——設置當DOM完成加載的時候綁定的函數

jQuery( callback ) 返回: jQuery

當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...
});


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章