我的代码看起来像:
$(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或如何暂停脚本几秒钟?
谢谢!
我尝试在更改窗口位置时丰富闪存效果,但是有一个小问题,我无法解决.
请看一下剧本
$(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,它工作正常.你能解释一下原因吗?
谢谢
我试图使用每个函数,并在每次迭代的执行之间暂停.具体来说,我希望脚本在新窗口中打开一堆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) 我试图用jQuery从页面中删除一个对象.我也想动画删除.目标是使元素fadeOut(),等待一秒,然后删除().但它似乎拒绝等待删除元素,即使我在setTimeout()函数中使用它.如何创建元素fadeOut(),然后删除()它?
$("button").click(function() {
$(this).fadeOut();
setTimeout(function() { $(this).remove();}, 1000);
});
Run Code Online (Sandbox Code Playgroud) 我编写了下面的程序,努力理解事件循环和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)
问题:
程序:
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) 我有一个单词数组,我想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()似乎没有发生任何事情.
我希望在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,似乎无法想出这个.
我有下面的匿名函数,它读取一个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的超时但是如何取消定时器mixin?建议Timermixin在Javascript超时时与React Native一起使用.
var TimerMixin = require('react-timer-mixin');
this.setTimeout(() => {this.setState({results: ' '})}, 1800)
Run Code Online (Sandbox Code Playgroud)
如果执行其他操作,我需要取消它.
我正在尝试使用一种方法创建一个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)
settimeout ×10
javascript ×9
jquery ×8
asynchronous ×1
delay ×1
each ×1
event-loop ×1
fadeout ×1
ios ×1
mixins ×1
node.js ×1
react-native ×1
return ×1