2012-10-24 43 views
-3

我如何setTimeout功能在這裏:setTimeout和jQuery的負載

function loadContent(url){ 
    jQuery(".post").fadeTo(200,0.5); 
     jQuery("#container").load(href + ' .posts', function(responseHtml){ 
      var newTitle = jQuery(responseHtml).filter('title').text(); 
      document.title = newTitle; 
    }); 
} 

我想是這樣的,但它不工作:

setTimeout(function(){ 
    jQuery("#container").load(href + ' .posts', function(responseHtml){ 
     var newTitle = jQuery(responseHtml).filter('title').text(); 
     document.title = newTitle; 
    }); 
}, 1000); 

我沒有得到任何錯誤。

+1

是什麼'?href'它在哪裏定義?並可以從控制檯發佈錯誤.. –

+0

href的定義如上href = jQuery(this).attr(「href」); 這裏是所有代碼http://pastebin.com/53yN5Esj,並沒有任何錯誤 – user1405674

回答

3

你應該改變你的功能。 替換負荷hrefurl

function loadContent(url){ 
    jQuery(".post").fadeTo(200,0.5); 
    jQuery("#container").load(url+ ' .posts', function(responseHtml){ 
     var newTitle = jQuery(responseHtml).filter('title').text(); 
     document.title = newTitle; 
    }); 
} 

,如果你想調用的setTimeout在loadCountent功能,你應該做這樣

function loadContent(url){ 
    jQuery(".post").fadeTo(200,0.5); 
    setTimeout(function(){ 
     jQuery("#container").load(url+ ' .posts', function(responseHtml){ 
      var newTitle = jQuery(responseHtml).filter('title').text(); 
      document.title = newTitle; 
     }); 
    }, 1000); 
} 
+1

@SheikhHeera,是的,它是加載頁面片段。 –

+0

哦!是的,我的錯誤,謝謝。 –