Este artículo resume los códigos de cuenta regresiva JS comunes. Compártelo para su referencia. El resumen específico es el siguiente:
El primer tipo: código de cuenta regresiva de JavaScript que es preciso para segundos
Código HTML:
Copie el código de la siguiente manera: <form de nombre = "form1">
<div align = "Center" align = "Center">
<center> todavía hay en 2010: <br>
<input type = "textarea" name = "izquierda" size = "35" style = "text-align: Center">
</Center>
</div>
</form>
<script language = "javaScript">
startClock ()
var timerID = null;
var timerrunning = false;
función showtime () {
Hoy = nueva fecha ();
var nowhour = Today.gethours ();
var nowMinute = Today.getMinutes ();
var nowmonth = Today.getMonth ();
var nowDate = Today.getDate ();
var nowyear = thay.getyear ();
var NowSecond = Today.getSeconds ();
if (nowyear <2000)
Nowyear = 1900+Nowyear;
Hoy = nulo;
Hourleft = 23 - Now Hour
Minuteleft = 59 - NowMinute
SecondLeft = 59 - Nowsecond
Anhipleft = 2009 - Nowyear
Montleft = 12 - Nowmonth - 1
DataLeft = 31 - ahora Date
if (SecondLeft <0)
{
SecondLeft = 60+SecondLeft;
Minuteleft = minuteleft-1;
}
if (minuteleft <0)
{
Minuteleft = 60+Minuteleft;
Hourleft = Hourleft-1;
}
if (hourleft <0)
{
Hourleft = 24+Hourleft;
DataLeft = dataLeft-1;
}
if (dataLeft <0)
{
DataLeft = 31+dataLeft;
Montleft = mestleft-1;
}
if (mes mest <0)
{
Mestleft = 12+mestleft;
Yearleft = Yearleft-1;
}
Temp = Yearleft+'año,'+mestleft+'mes,'+dataLeft+'día,'+horaft+'hora,'+minuteleft+'minuto,'+segundo+'segundo'
document.form1.left.value = temp;
timerID = setTimeOut ("showtime ()", 1000);
timerrunning = verdadero;
}
var timerID = null;
var timerrunning = false;
function stopClock () {
if (timerrunning)
ClearTimeOut (TimerID);
timerrunning = false;
}
función startClock () {
stopClock ();
tiempo de la funcion();
}
// ->
</script>
El segundo tipo: una determinada reunión deportiva
Código HTML:
Copie el código de la siguiente manera: <!-Countdown JavaScript Begin->
<script language = "javaScript">
<!-
function digitaltime1 ()
{
Fecha límite de var = nueva fecha ("13/08/2007") // abriendo cuenta atrás
símbolo var = "13 de agosto"
var ahora = nueva fecha ()
var diff = -480 - ahora.gettimezoneOffset () // es la diferencia de tiempo entre el tiempo de Beijing y la hora local
Var Leave = (Deadline.getTime () - ahora.gettime ()) + diff*60000
var day = Math.floor (Leave / (1000 * 60 * 60 * 24))
var hora = math.floor (licencia / (1000 * 3600)) - (día * 24)
var minuto = Math.floor (Leave / (1000 * 60)) - (día * 24 * 60) - (hora * 60)
var Second = Math.floor (Leave / (1000)) - (día * 24 * 60 * 60) - (hora * 60 * 60) - (minuto * 60)
VAR Falline_2 = nueva fecha ("13/08/2004") // después de la hora de apertura
VAR Symbol_2 = "13 de agosto"
var ahora_2 = nueva fecha ()
var diff_2 = -480 - ahora.gettimezoneOffset () // es la diferencia de tiempo entre el tiempo de Beijing y la hora local
var le quede_2 = (now_2.gettime () - fecha límite_2.gettime ()) + diff_2*60000
var day_2 = Math.floor (Leave_2 / (1000 * 60 * 60 * 24))
var hour_2 = Math.floor (Leave_2 / (1000 * 3600)) - (Day_2 * 24)
var minuto_2 = Math.floor (Leave_2 / (1000 * 60)) - (Day_2 * 24 * 60) - (Hour_2 * 60)
var Second_2 = Math.floor (Leave_2 / (1000)) - (Day_2 * 24 * 60 * 60) - (Hour_2 * 60 * 60) - (Minute_2 * 60)
día = día+1;
day_2 = day_2+1;
if (day> 0) // aún no se abre
{
//Liveclock1.innerhtml = "ahora"+símbolo+"día"
Liveclock1.innerhtml = "<font
setTimeout ("digitalTime1 ()", 1000)
}
if (día <0) // se ha abierto
{
//Liveclock1.innerhtml = "Ahora todavía hay"+día+"día+" día+"hora+" hora+"minuto+" minuto+"segundo+" segundo "
Liveclock1.innerhtml = "<font
setTimeout ("digitalTime1 ()", 1000)
}
If (day == 0) // abertura
{
//Liveclock1.innerhtml = "ahora"+símbolo+"día"
Liveclock1.innerhtml = "<font
setTimeout ("digitalTime1 ()", 1000)
}
if (day <0 & day_2> 19) // La reunión deportiva termina
{
//Liveclock1.innerhtml = "Ahora todavía hay"+día+"día+" día+"hora+" hora+"minuto+" minuto+"segundo+" segundo "
Liveclock1.innerhtml = "<font
setTimeout ("digitalTime1 ()", 1000)
}
}
// ->
</script>
<!-Countdown JavaScript End->
<Body Onload = DigitalTime1 ()>
<div id = liveclock1> </div>
</body>
El tercer tipo: Countdown de la hora
Código HTML:
Copie el código de la siguiente manera: <script language = "javaScript">
<!-
var maxtee = 60*60 // Una hora, calcule en segundos, ¡ajústelo usted mismo!
function Countdown () {
if (maxtee> = 0) {
minutos = Math.floor (MaxTime/60);
segundos = math.floor (maxtee`);
msg = "todavía hay" + minutos + "minutos" + segundos + "segundos" al final de la distancia;
document.all ["Timer"]. InnerHtml = msg;
if (maxtee == 5*60) alerta ('Nota, ¡quedan 5 minutos!');
-Axtime;
}
demás{
ClearInterval (temporizador);
alerta ("¡El tiempo está arriba, termina!");
}
}
timer = setInterval ("Countdown ()", 1000);
//->
</script>
<div id = "Timer" style = "color: rojo"> </div>
El cuarto tipo: la cuenta regresiva más simple
Código HTML:
Copie el código de la siguiente manera: <script language = "javaScript">
<!- Comienza
var timedate = nueva fecha ("14 de enero de 2006");
var tiempos = "examen de posgrado";
var ahora = nueva fecha ();
var date = timedate.gettime () - ahora.gettime ();
VAR TIME = MATH.FLOOR (fecha / (1000 * 60 * 60 * 24));
if (tiempo> = 0);
document.write ("<li> <font color =#dedbde> ahora todavía hay"+tiempos+"en 2006: <font color =#ffffff> <b>"+tiempo+"</b> </font> días </font> </li>");
// fin ->
</script>
El quinto tipo: la cuenta regresiva más simple dos
Código HTML:
Copie el código de la siguiente manera: <script language = "javascript" type = "text/javaScript">
función djs () {
var urodz = nueva fecha ("11/12/2008");
var ahora = nueva fecha ();
NUM
var ile = urodz.gettime () - ahora.gettime ();
var dni = math.floor (ile / (1000 * 60 * 60 * 24));
if (dni> 1)
num = dni+1
else if (dni == 1) num = 2
else if (dni == 0) num = 1
else num = 0
document.write (num)
}
</script>
Todavía hay días antes de la ceremonia de apertura de una determinada persona [<script language = "javascript" type = "text/javaScript"> djs () </script>]
Sexto: Temporizador de cuenta regresiva de JavaScript: auto -verificación del tiempo del sistema
Esta vez, la cuenta regresiva se verifica mediante la autoevaluación del tiempo del sistema, y no hay necesidad de un ajuste manual para hacer que la cuenta regresiva sea más precisa. El código y los comentarios detallados son los siguientes:
Copie el código de la siguiente manera: <span id = "reloj"> 00: 01: 11: 00 </span>
<input id = "startb" type = "button" value = "Start Countdown!" onClick = "run ()">
<input id = "endb" type = "button" value = "¡Detente cuenta cuenta con cuenta de!" onClick = "stop ()">
<br>
<input id = "diff" type = "text">
<input id = "next" type = "text">
<script language = "javaScript">
var normalelapse = 100;
var nextelapse = normalelapse;
Var contador;
var starttime tiempo;
var start = clock.inntext;
Var finalización = "00: 00: 00: 00";
VAR TIMER = NULL;
// Empiece a ejecutar
function run () {
startb.disable = true;
endb.disable = false;
contador = 0;
// Hora de inicio de inicialización
starttime = new Date (). ValueOf ();
// nextelapse es el tiempo de tiempo, inicialmente 100 milisegundos
// Tenga en cuenta la función setinterval: nextElapse (miliseconds) se pasa, Ontimer comienza a ejecutar
timer = window.setInterval ("Ontimer ()", nextLapse);
}
// deja de correr
function stop () {
startb.disable = false;
endb.disable = true;
Window.ClearTimeOut (temporizador);
}
window.onload = function () {
endb.disable = true;
}
// función de cuenta regresiva
function Ontimer ()
{
if (inicio == finalizar)
{
Window.ClearInterval (temporizador);
alerta ("¡TIEMPA ARRIBA!");
devolver;
}
var hms = new String (inicio) .split (":");
var ms = nuevo número (HMS [3]);
var s = nuevo número (HMS [2]);
var m = nuevo número (HMS [1]);
var h = nuevo número (HMS [0]);
MS -= 10;
if (ms <0)
{
MS = 90;
S -= 1;
if (s <0)
{
s = 59;
m -= 1;
}
if (m <0)
{
m = 59;
H -= 1;
}
}
var ms = ms <10? ("0" + MS): MS;
var ss = s <10? ("0" + S): S;
var sm = m <10? ("0" + m): m;
var sh = h <10? ("0" + H): H;
start = sh + ":" + sm + ":" + ss + ":" + ms;
clock.inntext = start;
// Borrar el último temporizador
Window.ClearInterval (temporizador);
// se obtiene la diferencia de tiempo del tiempo del sistema de auto-verificación y, por lo tanto, el tiempo del nuevo temporizador que se inicia la próxima vez se obtiene NextLapse NextLapse
contador ++;
Var contadores = contador * 100;
var elsepSeseCs = new Date (). ValueOf () - Starttime;
var diffsecs = Countterecs - elsepsesecs;
NextLapse = NormalElapse + DiffSecs;
diff.Value = Countsecs + "-" + elsepsesecs + "=" + diffSecs;
next.value = "nextelapse =" + nextelapse;
if (nextElapse <0) nextelapse = 0;
// Comenzar un nuevo temporizador
timer = window.setInterval ("Ontimer ()", nextLapse);
}
</script>
Espero que la descripción en este artículo sea útil para la programación web de todos basada en JavaScript.