Voici une petite méthode pour afficher l'heure en javascript :
1.Copier coller ce code entre <BODY> et </body>
| Code | <script language="JavaScript"><!--
// Helpers for JSI page...
// Netscapes Clock - Start
// this code was taken from Netscapes JavaScript documentation at
// www.netscape.com on Jan.25.96
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock () {
// Make sure the clock is stopped
stopclock();
showtime();
}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = " " + ((hours >23) ? hours -23 :hours)
timeValue += ((minutes < 10) ? "h0" : "h" ) + minutes
document.clock.face.value = timeValue;
// you could replace the above with this
// and have a clock on the status bar:
// window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
// Netscapes Clock - Stop
// end Helpers
// --></script>
<form name="clock" onsubmit="0">
<div align="center"><center><h4><font color="#0FF3FF"><strong><input type="text" size="5"
name="face" align="left"></strong></font></h4>
</center></div>
</form>
|
2.ajouter ce bout de code DANS la balise <BODY>:
| Code | onload="startclock()"
Exemple:
<body onload="startclock()">
|
V'la | |