Home > front end >  Page loading problem
Page loading problem

Time:05-13

 & lt; ! DOCTYPE html> 


<meta charset="utf-8" & gt;
<meta HTTP - equiv="X - UA - Compatible" content="IE=edge" & gt;
<meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;
Document
<style>
Div {
Width: 410 px;
height: 30px;
Border: 5 px solid # F00;
Padding: 15 px 10 px;
Background - color: # 0 f0;
margin: auto;
text-align: center;
}
</style>

<body>
<script>
Window. The onl oad=function () {
Var div=document. QuerySelector (' div ');
Var DayArray=[' on Sunday, Monday, Tuesday, Wednesday, ' ', 'on Thursday, Friday,' Saturday];
The function showTime () {
var now=new Date();
Var year=now. GetFullYear ();
Var month=now. GetMonth ();
Var date=now. GetDate ();
Var hour=now. GetHours ();
Var minutes=now. GetMinutes ();
Var seconds=now. GetSeconds ();
Var day=now. GetDay ();
If (seconds<10) {
Seconds='0' + seconds;
}
If (minutes<10) {
Minutes='0' + minutes;
}
Var time=year + + month 'years' +' month '+ date +', '+' '+' when '+ you + + hour' points' + seconds + 'seconds' +' '+ DayArray [day].
Div. InnerHTML='current system time:' + time;
SetTimeout (" showTime () ", 1000);
}
ShowTime ();
}
</script>




Why can't time continuous jump?

CodePudding user response:

SetTimeout ( showTime , 1000);

CodePudding user response:

All written out
ShowTime ()
SetInterval (function () {
ShowTime ();
}, 1000);

CodePudding user response:

SetTimeout () execute code only once, if you want to call for many times, please use the setInterval () or get code itself called again setTimeout (),
SetInterval () method can be according to the specified period (in milliseconds) to call a function or expression,
SetInterval () method will keep calling function, until clearInterval () is invoked or the window is closed, the setInterval () returns the ID value can be used as a clearInterval () method of parameters,

CodePudding user response:

reference LiuTianJi_00723 reply: 3/f
setTimeout () execute code only once, if you want to call for many times, please use the setInterval () or get code itself called again setTimeout (),
SetInterval () method can be according to the specified period (in milliseconds) to call a function or expression,
SetInterval () method will keep calling function, until clearInterval () is invoked or the window is closed, the setInterval () returns the ID value can be used as a clearInterval () method of the parameters,
I was inside the function use setTimeout (" showTime () ", 1000); Do not call all the time? Effect should be with setInterval outside the function call
  • Related