Home > Web Front-end > JS Tutorial > JavaScript uses the setInterval() function to implement simple polling operations_javascript skills

JavaScript uses the setInterval() function to implement simple polling operations_javascript skills

WBOY
Release: 2016-05-16 16:16:28
Original
11267 people have browsed it

The example in this article describes how JavaScript uses the setInterval() function to implement a simple polling operation. Share it with everyone for your reference. The specific analysis is as follows:

Polling is a way for the CPU to decide how to provide peripheral device services, also known as "Programmed I/O". The concept of the polling method is that the CPU issues queries regularly, asking each peripheral device in sequence whether it needs its service. If it needs service, it will provide the service. After the service is completed, it will ask the next peripheral device, and then the cycle will continue. The polling method is easy to implement, but its efficiency is low.

Use the setInterval function in JavaScript to perform a simple polling operation. You can determine a parameter value at any time without refreshing the page, that is, without adding

1. Basic goals

As shown in the figure, there is an input box. Instead of using the onChange() function, use the setInterval function directly to perform a simple polling operation, and read the contents of the text box every 0.5 seconds

In fact, the principle is the same as the JavaScript clock. It takes the current time every second and then updates the text content

2. Production process

The code is as follows, I won’t go into details again:

Copy code The code is as follows:




Polling








The polling() function starts executing after the page is loaded. It executes the synchronous() function first, and then always executes synchronous() every 0.5 seconds; function

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template