2012-10-24 31 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

哦!是的,我的错误,谢谢。 –