标签: settimeout

如何使用setTimeout()调用jQuery(document).ready之外的函数?

我的代码看起来像:

$(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
    }
    }
});
Run Code Online (Sandbox Code Playgroud)

所以我想做的是延迟执行func1(续); 在searchComplete()函数内部.这样做的原因是所有代码都是使用Google搜索API和PageRank检查,我需要放慢脚本速度,这样我才不会被禁止.(特别是关于公关检查的要求).如果我只是在func1(cont)上使用setTimeout(); 它说没有定义func1(),如果我试图在$(document).ready()之外获取该函数,它会看到该函数,但Google代码不会因为它需要完全加载的页面.

如何修复setTimeout或如何暂停脚本几秒钟?

谢谢!

javascript jquery settimeout

1
推荐指数
1
解决办法
1万
查看次数

setTimeout不能与window.location一起使用?

我尝试在更改窗口位置时丰富闪存效果,但是有一个小问题,我无法解决.

请看一下剧本

 $(document).ready(function(){

            $('a.flash').click(function(e) {
                e.preventDefault();
                $('body').fadeOut(1500);
                setTimeout("", 1500);
                window.location=this.href;
            }); 
      });
Run Code Online (Sandbox Code Playgroud)

window.location=this.href必须在1500ms后完成,但不会发生.你能解释一下原因吗?有什么奇怪的,当我尝试写alert("something");而不是window.location=this.href,它工作正常.你能解释一下原因吗?

谢谢

javascript jquery settimeout

1
推荐指数
1
解决办法
5632
查看次数

jquery每次延迟都没有效果

我试图使用每个函数,并在每次迭代的执行之间暂停.具体来说,我希望脚本在新窗口中打开一堆URL,但我希望每个窗口之间有2秒的暂停.现在,每个链接都打开,两者之间没有暂停.以下是我的代码.我不知道如何使用delay()函数,因为我不会在延迟后调用另一个jQuery效果.我也试过setTimeout无济于事.我错过了什么?

    $('.url').each(function() {
        url = $(this).attr("href");
        window.open('http://www.google.com' + url);
    });
Run Code Online (Sandbox Code Playgroud)

each jquery delay settimeout

1
推荐指数
1
解决办法
2724
查看次数

在jQuery中删除元素的问题

我试图用jQuery从页面中删除一个对象.我也想动画删除.目标是使元素fadeOut(),等待一秒,然后删除().但它似乎拒绝等待删除元素,即使我在setTimeout()函数中使用它.如何创建元素fadeOut(),然后删除()它?

$("button").click(function() {
    $(this).fadeOut();
    setTimeout(function() { $(this).remove();}, 1000);
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery settimeout fadeout

1
推荐指数
2
解决办法
313
查看次数

node.js和setTimeout以及setInterval - 理解事件循环

我编写了下面的程序,努力理解事件循环和setTimeout和setInterval等函数.

该计划的输出与我的预期不同:

输出是:

In F
In L
Padalia
outside all
callback1
callback2
From Interval:0
From Interval:1
From Interval:2
From Interval:3
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 为什么"oustside all"不是先执行?
  2. 为什么间隔总是最后执行?
  3. 有人能解释我整个程序的执行情况.
  4. 在退出程序之前等待一段时间,为什么?

程序:

var Fname = undefined;
var Lname = undefined;
var count = 0;

function F(callback){
  console.log("In F");
  Fname = "Rushabh";
  if(Fname != undefined && Lname != undefined) { 
    console.log(Fname);
    }      
  process.nextTick(function() { 
    callback();
  });
//callback();
}

function L(callback){
  console.log("In L");
  Lname = "Padalia";
  if(Fname != undefined && Lname != undefined) { 
    console.log(Lname);
  } 
  process.nextTick(function() …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous event-loop settimeout node.js

1
推荐指数
1
解决办法
4622
查看次数

带有循环的jQuery中的setTimeout

我有一个单词数组,我想div按顺序将标签更改为每个单词.

<script>
    function printWord(w) {
    setTimeout(function() {
        $("#word").text(w);
        }, 1000);

     }

function readBook() {
    var array = $("#offscreen_text").text().toString().split(/[\s\n]+/);
    for (i =1; i < array.length; i++){
        printWord(array[i]);
    }

}
</script>
<body onload="readBook()">
<div id="word"></div>
<div id="offscreen_text">hi hello bye goodbye this is a test with some random text</div>
</body>
Run Code Online (Sandbox Code Playgroud)

当我跑步时readBook()似乎没有发生任何事情.

javascript jquery settimeout

1
推荐指数
1
解决办法
2565
查看次数

Javascript在500毫秒后执行功能,但在按键时返回

我希望在500ms之后执行一个javascript函数,但是在按下某个键时不会,例如:

jQuery(function($) {
    $('.class').keyup(function(Key) {
         setTimeout(function(){
              // excecute this not when any key is pressed
         },500)
    })
})
Run Code Online (Sandbox Code Playgroud)

javascript jquery return settimeout

1
推荐指数
1
解决办法
663
查看次数

在加载时执行匿名函数,然后使用setTimeout每30秒再次执行

对不起,如果已经回答了这个问题,我只是在学习Javascript,似乎无法想出这个.

我有下面的匿名函数,它读取一个json文件并更新html.它每30秒成功更新一次,问题是我必须等待30秒才能在页面加载时显示数据.如何修改下面的代码,以便在加载时更新,然后每30秒更新一次?

$(function () {
  setTimeout(function() {
  $.ajaxSetup({ cache: false });  
  $.getJSON("data/ticket_data.json", function(result){
  /*some more stuff here*/
  });
},30000);
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery settimeout

1
推荐指数
1
解决办法
54
查看次数

React Native timemixin取消计时器超时

我发现了如何取消Javascript的超时但是如何取消定时器mixin?建议Timermixin在Javascript超时时与React Native一起使用.

var TimerMixin = require('react-timer-mixin');

this.setTimeout(() => {this.setState({results: ' '})}, 1800)
Run Code Online (Sandbox Code Playgroud)

如果执行其他操作,我需要取消它.

javascript mixins settimeout ios react-native

1
推荐指数
1
解决办法
5370
查看次数

setTimeout的递归方法

我正在尝试使用一种方法创建一个js对象,该方法将逐字母打印,每个字母之间有5秒的延迟.但是现在还没有运行.它毫不拖延地写出来.我的错误在哪里?

class autoWrite{
    constructor(id,text){
        this.id = id;
        this.text = text;
    }
    startTyping(index=0){
        if(index==this.text.length){
            console.log("finish");
        }
        else{
            $("#"+this.id).append(this.text.charAt(index));
            setTimeout(this.startTyping(index+1),5000);
        }
    }
}
 a = new autoWrite("body-window","hello world");
 a.startTyping();
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <div id="body-window">

</div>
Run Code Online (Sandbox Code Playgroud)

javascript jquery settimeout

1
推荐指数
1
解决办法
94
查看次数