Feedback system time with javascript
Applying knowledge
JavaScript HTML DOM
The setInterval() method in HTML DOM will keep calling the function until clearInterval() is called or the window is closed. The ID value returned by setInterval() can be used as a parameter to the clearInterval() method.
grammarsetInterval(code,milliseconds)
code - code (can be a function)
milliseconds—Time to call this (milliseconds)
Therefore, if we want to make the feedback system time move, we just need to make the displayed time move like an alarm clock without calling the method once every 1000 milliseconds.
setInterval(function(){myTimer()},1000)
new Date()//Get the current time.toLocaleTimeString()//Convert the time part of the Date object to a string according to the local time.getElementById("clock")//Return element with specified ID.innerHTML=c; //WillcReturn to the specified element
Code section
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div ></div> </body> <script> var a = setInterval(function(){myTimer()},1000); function myTimer(){ var b = new Date(); var c = (); ("clock").innerHTML=c; } </script> </html>
Summarize
The above is the pure JavaScript real-time feedback system time introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!