我的代码看起来像这样:
$(document).ready(function(){
var cont = 0;
function func1(cont)
{
//Some code here
search.setSearchCompleteCallback(this, searchComplete, null);
//Some other code
}
func1(cont);
function searchComplete()
{
//Some code
cont += 1;
if (cont < length ) {
func1(cont);
} else {
// Other code
}
}
});
所以我想做的是延迟func1(cont)的执行;在 searchComplete() 函数内部。这样做的原因是所有代码所做的都是与 Google 搜索 API 和 PageRank 检查一起工作,我需要放慢脚本速度,这样我才不会被禁止。 (特别是对于它提出的有关 PR 检查的请求)。 如果我只是在 func1(cont) 上使用 setTimeout();它说没有定义 func1(),如果我尝试在 $(document).ready() 之外获取该函数,它会看到该函数,但 Google 代码不会,因为它需要页面完全加载。
如何修复 setTimeout 或如何暂停脚本数秒?
谢谢!
最佳答案
写
func1(cont);
作为
window.setTimeout(function() {
func1(cont);
}, 1000);
关于javascript - 如何使用 setTimeout() 调用 jQuery(document).ready 之外的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1375722/