Recentemente, estamos fazendo o projeto da loteria do arranjo cinco. Cada período tem um período de compra de loteria. Ou seja, quando o usuário abre esse acordo de cinco páginas, uma restante será enviada do servidor (o tempo restante antes do final deste período da loteria) e, em seguida, esse tempo será apresentado ao usuário do lado do cliente, permitindo que o usuário obtenha o tempo restante deste período da loteria.
O princípio da implementação é bastante simples. Não vou entrar em detalhes aqui. Execute o código a seguir para ver a demonstração:
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = gbk"/> <title> Índice </title> <estilo type = "text/css"> em {color:#f00;} </style> </style </" type = "text/javascript"> var thetime = function () {this.init.apply (this, argumentos);}; theTime.prototype = {init: function (obj) {var que = this; obj = that.buildparam (obj); that.callback = obj.callback; var container = that.Container = document.getElementById (obj.Container); container.innerhtml = '<em> </em> hora <em> </em> minuto <em> </em> segundos'; var hourspace = that.hourspace = container.getElementsByTagName ('em') [0]; var miniSpace = that.minutespace = container.getElementsByTagName ('em') [1]; var Secondspace = that.secondspace = container.getElementsByTagName ('em') [2]; if (obj.reMaintime == 0) {that.ResetTime (); retornar; } that.hours = math.floor (obj.remaintime/3600); that._remaainder1 = obj.remaintime % 3600; that.minutes = math.floor (that._remaainder1/60); that.Seconds = that._remaainder1 % 60; var timer = that.timer = setInterval (function () {that.RenderTime.Apply (que);}, 1000); }, BuildParam: function (obj) {obj = {// contêiner é o contêiner de identificação do nó DOM: obj.container || 'Container', permanece: número (obj.remaintime) || 0, // Retorno de chamada após a contagem regressiva ser concluída: obj.callback || nova função}; retornar obj; }, resettime: function () {var que = this; that.container.innerhtml = "deadlined"; }, // Referência de tempo de atualização: function () {// depurador; var que = this; if (that.seconds> 0) {that.Seconds--; } else {that.seconds = 59; if (that.Minutes> 0) {that.minutes--; } else {that.minutes = 59; if (that.hours> 0) {that.hours--; }}} // em espera if (that.hours == 0 && that.minutes == 0 && that.seconds == 0) {// Execute o retorno de chamada que._callback (); } var Bithandle = that.bithandle; var _hour = bithandle (that.hours); var _Minute = bithandle (that.Minutes); var _second = bithandle (that.seconds); that.hourspace.innerhtml = _hour; that.minutespace.innerhtml = _Minute; that.secondspace.innerhtml = _second; }, // Para processamento de bits, retorne um número de dois dígitos Bithandle: function (num) {var str = num.toString (); if (str.Length <2) {str = 0 + str; } retornar str; }, _Callback: function () {var que = this; ClearInterval (that.timer); that.callback (); }}; novo tempo ({// contêiner de ID do contêiner: 'REMANTIME', // O tempo restante retornado pelo servidor, a unidade é o tempo restante dos segundos: 10000, // retorno de chamada quando a contagem regressiva é concluída de chamada: function () {Document.getElementById ('Remantime').