2011-10-02 127 views
1

我需要一点指导。我试图延迟这两个函数的执行,直到页面完全加载或者在5000毫秒之后对它们进行定时炸弹。jquery延迟执行函数

我使用了最新的jQuery 1.6

预先感谢您的帮助和代码snippits :)

$("a.siteNavLink").each(function() { 
    var _href = $(this).attr("href"); 
    $(this).attr("href", _href + '?p=client'); 
}); 
$("a.footernav").each(function() { 
    var _href = $(this).attr("href"); 
    $(this).attr("href", _href + '?p=client'); 
}); 

回答

2
$(document).ready(function() { 
    // Your code here 
}); 

这将使你的代码运行,只有当文档完全加载

jQuery ready() documentation

+0

所以沿着这些线路 '$(文件)。就绪(函数(){ $( “a.footernav”)。每个(函数(){ VAR _href = $(this).attr(“href”); $(this).attr(“href”,_href +'?p = client'); }); });' –

+0

是的,看起来不错:-) – Clive

+0

....忘了把页面上的链接jquery-1.6.4.min.js文件... facepalm –

3

您可以使用

$(window).load(function(){ your code here }) // page has loaded including images 

$(document).ready(function(){ your code here }) // dom has loaded