1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Décompte JavaScript</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Décompte JavaScript (C)1997 Cyril Pannetier - La Petite Boutique Java & JavaScript -
// web : http://www.mygale.org/08/pannetie
// e-mail : pannetie@mygale.org
// Ce script est librement utilisable. Merci de ne pas effacer ces commentaires.
var Mois = new Array(12);
var Jours = new Array(7);
function Decompte(msg1,msg2,endmsg,datetemoin,cible,Fonction) {
this.Target = cible;
this.fonction = Fonction + '.Affiche()'; // Nom de l'objet JavaScript
this.timeout = null;
this.datebase = new Date(datetemoin);
this.mesg1 = msg1;
this.mesg2 = msg2;
this.end = endmsg;
this.ToStop = false;
this.Init = Initialise;
this.Affiche = Affichage;
this.Stop = StopAll;
this.Init();
this.Affiche();
}
function Initialise() {
var cur = new Date();
var diff = this.datebase.getTime() - cur.getTime();
this.ToStop = (this.end != '');
}
function Affichage() {
var out;
curdate = new Date();
if ( (this.ToStop) && ( (this.datebase.getTime() - curdate.getTime()) <= 0 ) ) {
if (this.Target == "") {
window.status = this.end;
}
else {
this.Target.value = this.end;
}
StopAll();
}
else {
difference = Math.abs(this.datebase.getTime() - curdate.getTime());
difference = Math.floor(difference / 1000);
nbj = Math.floor(difference / 86400);
difference = difference % 86400;
nbh = Math.floor(difference / 3600);
difference = difference % 3600;
nbm = Math.floor(difference / 60);
difference = difference % 60;
nbs = difference;
out = this.mesg1 + ' ' + nbj;
if (nbj == 1)
out += ' jour ' + nbh;
else
out += ' jours ' + nbh;
if (nbh == 1)
out += ' heure ' + nbm;
else
out += ' heures ' + nbm;
if (nbm == 1)
out += ' minute ' + nbs;
else
out += ' minutes ' + nbs;
if (nbs == 1)
out += ' seconde ' + this.mesg2;
else out += ' secondes ' + this.mesg2;
if (this.Target == "") {
window.status = out;
}
else {
this.Target.value = out;
}
this.timeout = window.setTimeout(this.fonction,1000);
}
}
// Fonction Arret
function StopAll() {
clearTimeout(this.timeout);
this.timeout = null;
}
//-->
</SCRIPT>
</HEAD>
<BODY onLoad = "LeDecompte = new Decompte('','','Bonne Année. Bienvenue dans le nouveau millénaire!','30 nov, 2009 21:36:00',document.JSCLOCK.CLOCK,'LeDecompte');"
onUnload = 'LeDecompte.Stop();'>
<H1>Décompte de temps en JavaScript : Jusqu'à une date donnée</H1>
<HR>
<CENTER>
<FORM NAME="JSCLOCK">
<INPUT NAME="CLOCK" SIZE=40 VALUE="champ 1"><BR>
</FORM>
</CENTER>
<HR>
</BODY>
</HTML> |
Partager