Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the timing event of javascript

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to realize the timing events 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!

In JavaScript, the basic unit of timing is milliseconds; timing events in JavaScript, that is, objects allow code to be executed at specified intervals, all of which are timed in a specified number of milliseconds.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

What is the basic unit of timing in javascript

JavaScript can be executed during the interval.

This is called timing event (Timing Events).

Timing event

The window object allows code to be executed at specified intervals.

These intervals are called scheduled events.

There are two key methods used through JavaScript:

SetTimeout (function, milliseconds)

Executes the function after waiting for the specified number of milliseconds.

SetInterval (function, milliseconds)

Equivalent to setTimeout (), but the function is executed repeatedly over and over again.

Both setTimeout () and setInterval () are methods of the HTML DOM Window object.

Examples are as follows:

SetTimeout () method

Window.setTimeout (function, milliseconds)

The window.setTimeout () method can be written without the window prefix.

The first argument is the function to be executed.

The second parameter indicates the number of milliseconds before execution.

Click "try". Wait 3 seconds and the page will prompt "Hello".

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report