banner2.gif (3664 bytes)
FreeBRS - Sistema de informações desenvolvida pela BRS - Brasil Site (Tudo Gratuito)
 


Cronômetro

Código HTML necessário:


<SCRIPT LANGUAGE="JavaScript"> <!-- // Copyright (c) 1996 Tomer Shiran. All rights reserved. // Permission given to use this script provided that the copyright // notice remains as is. Additional scripts and information are // available at http://www.geocities.com/SiliconValley/9000/ // set initial values var timerRunning = false var timerID = null // create instance of Date object representing current time var initial = new Date() // start timer function start() { // set the button's label to "stop" document.forms[0].general.value = "stop" // assign the stop function reference to the button's onClick event handler document.forms[0].general.onclick = stop // ask the user if to reset the timer if (confirm("Você deseja reiniciar o contador?")) // set global variable to new time initial = new Date() // assign milliseconds since 1970 to global variable startTime = initial.getTime() // make sure the timer is stopped stopTimer() // run and display timer showTimer() } // set button to initial settings function stop() { // set the button's label to "Iniciar" document.forms[0].general.value = "start" // assign the start function reference to the button's onClick event handler document.forms[0].general.onclick = start // stop timer stopTimer() } // stop timer function stopTimer() { // if the timer is currently running if (timerRunning) // clear the current timeout (stop the timer) clearTimeout(timerID) // assign false to global variable because timer is not running timerRunning = false } function showTimer() { // create instance of Date representing current timer var current = new Date() // assign milliseconds since 1970 to local variable var curTime = current.getTime() // assign difference in milliseconds since timer was cleared var dif = curTime - startTime // assign difference in seconds to local variable var result = dif / 1000 // is result is not positive if (result < 1) // attach an initial "0" to beginning result = "0" + result // convert result to string result = result.toString() // if result is integer if (result.indexOf(".") == -1) // attach ".00" to end result += ".00" // is result contains only one digit after decimal point if (result.length - result.indexOf(".") <= 2) // add a second digit after point result += "0" // place result in text field document.forms[0].display.value = result // call function recursively immediately (must use setTimeout to avoid overflow) timerID = setTimeout("showTimer()", 0) // timer is currently running timerRunning = true } // --> </SCRIPT> <CENTER> <P><FORM><INPUT TYPE="text" NAME="display" VALUE="" onFocus="this.blur()"><INPUT TYPE="button" NAME="general" VALUE="Iniciar" onClick="start()"></FORM></P></CENTER>

voltar para o menu anterior