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: