In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how many kinds of timers of javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
There are two kinds of timers in javascript: 1, a single timer, which is defined by the setTimeout () method, which can execute a code block after a specified time (in milliseconds); and 2, a loop timer, which uses the setInterval () method definition to repeat some code according to the specified period (in milliseconds).
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
In JavaScript, we can use timers to delay the execution of some code or to repeat some code at regular intervals. For example, you can use a timer to regularly update advertisements on a page or display a real-time clock, and so on.
Two timers are provided in JavaScript: setTimeout () and setInterval ()
The method states that setTimeout () executes some code after the specified time (in milliseconds). The code will only execute setInterval () once to repeat the execution of some code in the specified period (milliseconds). The timer will not stop automatically unless the clearInterval () function is called to manually stop or close the browser window.
SetTimeout ()
The JS setTimeout () function is used to execute some code after a specified time, and the code is executed only once.
How to use it:
SetTimeout (code,millisec)
Code is required. The JavaScript code string to be executed after the function to be called.
Millisec is required. The number of milliseconds to wait before executing the code.
Example:
Get the verification code var time = 10; var num; var button = document.getElementById ("button"); var span = document.getElementById ("span") Function set () {num = setInterval ("click ()", 1000); button.disabled = true } function click () {if (time = = 0) {button.disabled = false; time = 10 Span [XSS _ clean] = ""; clearInterval (num) } else {Span [XSS _ clean] = time + "get the return value in seconds" time-- This is the end of the content of "what kinds of timers of javascript". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.