聲明$(function(){})的含義

使用jquery開發項目時,常常在js文件中看到這樣的語句:

$(function() {
	$("#titleDiv").load("content.do?type=list");
})

是什麼意思呢?這其實是一個jQuery函數,是當文檔載入完成的時候執行的,也就是說文檔載入完成後,執行:

$("#titleDiv").load("content.do?type=list");

這裏執行相當於:

 $(document).ready(function(){ 
    $("#titleDiv").load("content.do?type=list");
 })

當然,如果兩種方式都有的話:

 $(document).ready(function(){ 
    $("#titleDiv").load("content.do?type=list");
 })

$(function(){
  $("#titleDiv").load("content.do?type=list");
 });

那麼,先執行

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

再執行:

$(function(){})

轉載自:http://blog.csdn.net/dongdong9223/article/details/50504518

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