Tema: Reloj con JS
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/03/2003, 02:11
Avatar de caricatos
caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 24 años, 6 meses
Puntos: 1284
Hola AeSePe1:

Aquí tienes un ejemplo:

Código PHP:
<html>
<
head>
<
script language="javascript" >
var 
minutero = 0;
var 
segundero = 0;
var 
horario = 0;
var 
activo = false;

function 
ajuste(n)    {
    var 
salida = "";
    if (
n < 10)    salida = "0" + n ;
    else 
salida = "" + n;
    return 
salida;
}

function 
iniciaReloj()    {
    if (
activo) {alert("Fin cuenta"); location.reload()}
    
activo = true;
    
document.digital.boton.value = "Terminar...";
    
document.digital.segundo.value = ajuste(segundero);
    
document.digital.minuto.value = ajuste(minutero);
    
document.digital.hora.value = ajuste(horario);
    
setTimeout("ponSegundero()", 1000);
}

function 
ponSegundero()    {
    if (++
segundero > 59)    {
        
ponMinutero();
        
segundero = 0;
    }
    
document.forms.digital.segundo.value = ajuste(segundero);
    
setTimeout("ponSegundero()", 1000);
}

function 
ponMinutero()    {
    if (++
minutero > 59)    {
        
ponHora();
        
minutero = 0;
    }
    
document.forms.digital.minuto.value = ajuste(minutero);
}

function 
ponHora()    {
    if (++
horario > 23)    horario = 0;
    
document.forms.digital.hora.value = ajuste(horario);
}
</script>

</head>
<body >

<center>
<table>
<form name=digital>
<tr>
<td><input type=text name=hora size=2 value="00" disabled style="border:0" >:</td>
<td><input type=text name=minuto size=2 value="00" disabled style="border:0" >:</td>
<td><input type=text name=segundo size=2 value="00" style="border:0" disabled></td>
</tr>
<tr>
<td colspan=3>
<input type=button name=boton value="inicia Cuenta" onClick="iniciaReloj()">
</td>
</tr>
</table>
</form>
</center>
</body>
</html> 
Espero que te sirva

Saludos