Home Web Front-end JS Tutorial Solution to the error when calling setTimeout() recursively without quotation marks_javascript skills

Solution to the error when calling setTimeout() recursively without quotation marks_javascript skills

May 16, 2016 pm 04:37 PM
settimeout recursive call

I used setTimeout() to implement a recursive call. If the first parameter is not quoted, Firefox will prompt setTimeout():uselesssetTimeout call (missing quotes around argument?). If it is quoted, Firefox will prompt that the function is undefined

function refreshNum() { 
$.ajax({ 
type: "POST", 
url: "ajax/RefreshNum.ashx", 
async: false, 
data: {}, 
success: function (data) { 
varnumArry = data.split(','); 
$.each($(".rush_left"), function (n) { 
$(this).children().eq(0).html(numArry[n]); 
}); 
setTimeout(function () { refreshNum(); }, 3000); 
//setTimeout("refreshNum",3000); //这样写就会出错,setTimeout()函数的参数,第一个一定不要用简单的函数调用,而是使用匿名函数!至于为什么就不知道了 
} 
}); 

} 
refreshNum();
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between settimeout and setinterval What is the difference between settimeout and setinterval Aug 15, 2023 pm 02:06 PM

The difference between settimeout and setInterval: 1. Trigger time, settimeout is one-time, it executes the function once after setting the delay time, while setinterval is repetitive, it will execute the function repeatedly at the set time interval; 2. Execution times, settimeout is only executed once, and setinterval will be executed repeatedly until canceled.

What is the relationship between recursive calls and exception handling in Java functions? What is the relationship between recursive calls and exception handling in Java functions? May 03, 2024 pm 06:12 PM

Exception handling in recursive calls: Limiting recursion depth: Preventing stack overflow. Use exception handling: Use try-catch statements to handle exceptions. Tail recursion optimization: avoid stack overflow.

What is the memory consumption of recursive calls in Java functions? What is the memory consumption of recursive calls in Java functions? Apr 30, 2024 pm 12:09 PM

Recursive calls in Java functions consume memory because each recursive call creates a new stack frame on the stack. To avoid stack overflow errors, you can limit the recursion depth, perform tail recursion optimization, or use loops instead of recursion.

Recursive calling of Go language functions and practical application scenarios Recursive calling of Go language functions and practical application scenarios Mar 22, 2024 pm 09:42 PM

Title: Recursive Calling of Go Language Functions and Practical Application Scenarios In the Go language, recursive calling of functions is a powerful programming technique that can solve certain complex problems concisely. Recursive calling refers to a function calling itself directly or indirectly. By splitting a large problem into multiple similar small problems, recursive calling can help us better understand, design and implement algorithms. 1. What is recursive call? When a function calls itself during execution, this method of calling is called recursive call. Recursive functions need to satisfy two requirements when implementing them:

Implementation method of recursive calling of Golang function Implementation method of recursive calling of Golang function May 17, 2023 pm 07:21 PM

Implementation method of recursive calling of Golang functions With the wide application of Golang in software development, recursive calling of functions has become an important means for programmers to implement complex logic and algorithms. Recursive calling refers to continuously calling itself within a function until a certain condition is met to terminate the loop. In this article, we will explore the implementation of recursive calling of Golang functions. 1. Basic definition of recursive call Recursive call refers to the process of calling itself within a function. During the execution of a recursive function, it is necessary to determine the termination conditions. If the conditions are met

How do recursive calls to PHP functions affect execution order? How do recursive calls to PHP functions affect execution order? Apr 17, 2024 pm 02:03 PM

PHP function recursive calls affect the execution order and follow the last-in-first-out stack structure: when a function calls itself recursively, it is pushed onto the stack. The last function on the stack is executed first. When the function returns, it is popped off the stack and the calling function continues execution.

Use the clearTimeout function in JavaScript to cancel the setTimeout timer Use the clearTimeout function in JavaScript to cancel the setTimeout timer Nov 18, 2023 am 08:05 AM

To use the clearTimeout function in JavaScript to cancel the setTimeout timer, you need specific code examples. In JavaScript, the setTimeout function is used to execute a specific code after a specified time delay. The setInterval function is used to repeatedly execute a specific code within a specified time interval. However, in some cases we may need to cancel the timer before it executes. In this case, you can use c

What is the difference between setTimeout() and setInterval() in JavaScript? What is the difference between setTimeout() and setInterval() in JavaScript? Sep 01, 2023 pm 03:01 PM

setTimeout(function,duration) - This function calls the function after duration milliseconds. This works for one execution. Let's see an example - it waits for 2000 milliseconds and then runs the callback function alert('Hello') - setTimeout(function(){alert('Hello');},2000); setInterval(function,uration) - this function is The function is called after every duration milliseconds. This can be done an unlimited number of times. Let's see an example - it triggers an alarm every 2000 ms

See all articles