(1): First, write the function clockon () for real-time system time display in JS. There is only one parameter bgclock, which is used to specify the name of the <div> flag used for display after conversion. No return value is returned, during website development, you can save the function modification in the JS file to reuse the Code as follows:
Copy codeThe Code is as follows:
<Script>
Function clockon (bgclock)
{
Var now = new Date ();
Var year = now. getYear ();
Var month = now. getMonth ();
Var date = now. getDate ();
Var day = now. getDay ();
Var hour = now. getHours ();
Var minu = now. getMinutes ();
Var sec = now. getSeconds ();
Var week;
Month = month + 1;
If (month <10) month = "0" + month;
If (date <10) date = "0" + date;
If (hour <10) hour = "0" + hour;
If (minu <10) minu = "0" + minu;
If (sec <10) sec = "0" + sec;
Var arr_week = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
Week = arr_week [day];
Var time = "";
Time = year + "year" + month + "month" + date + "day" + week + "" + hour + ";" + minu + ";" + sec;
If (document. all)
{
Bgclock. innerHTML = "[" + time + "]"
}
Var timer = setTimeout ("clockon (bgclock)", 200 );
}
</Script>
(2): Call the <body> onload event on the page and place the div tag code in the area to be displayed:
Copy codeThe Code is as follows:
<Body onLoad = "clockon (bgclock)">
<Div id = "bgclock" class = "word_Green"> </div>
</Body>