DevKB
Web Development Knowledge Base
HOME | TOP 20 | WRITE AN ARTICLE |
Sections :



RSS RSS Feed

You too, please publish your useful code snippets in any programming language :
write an article !


Valid HTML 4.0 Transitional

Plateforme d'envoi de gros fichiers en ligne
Dépannage site web
Blog infogérance
Hébergement e-mail

Aurélie Dufour - - 19/03/2008 - vue 15385 fois

Un compteur en Javascript

Un simple compteur numérique incrémental qu'on peut lancer, stopper puis redémarrer d'un clic :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Minuterie en JS</title>
<style type="text/css">
body{
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10pt;
	}
</style>
<script type="text/javascript">
var compteur = 1;
var interv;
var encours;

function incrementer()
{
	compteur++;
	document.formulaire.heure.value=compteur;
}

function appui()
{
	if(encours == 1)
	{
		clearInterval(interv);
		document.formulaire.bouton.value = "Reprendre";
		encours = 0;
	}
	else 
	{
		interv = setInterval("incrementer()",100);
		document.formulaire.bouton.value = "Arrêter";
		encours = 1;
	}
}

function init()
{
	// (pas de démarrage auto) interv = setInterval("incrementer()",100);
	document.formulaire.bouton.value = "Commencer";
}
</script>
</head>

<body onload="init();">
<h2>Un compteur en JS</h2>
<form name="formulaire">
<input type="text" value="" name="heure" onclick="incrementer();"/>
<input type="button" value="Arreter" onclick="appui();" name="bouton" />
</form>

</body>
</html>



Write a comment :
Your name :     E-mail (optional) :

AntiSpam : what animal is visible on this picture ? :

Nos partenaires : iPhone 8 Cases & Protection