+ 3
Why body? I mean, what it means? (Document.body.innerHTML)
function printTime() { var d = new Date(); var hours = d.getHours(); var mins = d.getMinutes(); var secs = d.getSeconds(); document.body.innerHTML = hours+":"+mins+":"+secs; } setInterval(printTime, 1000);
3 ответов
+ 6
innerHTML sets or gets the content of an element.
in your code, the body element will get its content set to the current time periodically every 1 second (1000 miliseconds)
also, i would recommend assigning some value to setInterval so you can clear it later (not required in this code, just good practice)
var clockInterval=setInterval(printTime,1000);
.....
some time later when we want to stop the clock but not the entire program, we'll call
clearInterval(clockInterval);
which will stop the periodic calling to printTime.
+ 2
thanks
0
It means the <body> element of the page you write the script for