Skip to content

Instantly share code, notes, and snippets.

@JuanjoSalvador
Created October 26, 2015 09:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanjoSalvador/0545c414059d318b442b to your computer and use it in GitHub Desktop.
Save JuanjoSalvador/0545c414059d318b442b to your computer and use it in GitHub Desktop.
Cronometro en JavaScript
<html>
<head>
<title>Cronómetro</title>
<meta charset="utf-8">
<script>
var cronos;
var tiempo;
function init() {
cronos = setInterval(function() { timer() }, 1000);
}
function timer() {
tiempo = parseInt(document.getElementById('time').value);
document.getElementById('time').value = eval(tiempo + 1);
}
function reset() {
tiempo = parseInt(document.getElementById('time').value);
document.getElementById('time').value = "0";
}
function stop() {
clearInterval(cronos);
}
</script>
</head>
<body>
<input type="button" value="Empezar" onclick="init()" />
<input type="button" value="Reiniciar" onclick="reset()" />
<input type="button" value="Parar" onclick="stop()" />
<input id="time" name="time" value="0" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment