10秒倒计时JS代码

JavaScript012

10秒倒计时JS代码,第1张

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script type="text/javascript">

<!--

var duration=9900

var endTime = new Date().getTime() + duration + 100

function interval()

{

var n=(endTime-new Date().getTime())/1000

if(n<0) return

document.getElementByIdx("timeout").innerHTML = n.toFixed(3)

setTimeout(interval, 10)

}

window.onload=function()

{

setTimeout("window.location.href='http://www.17mm.net'", duration)

interval()

}

//-->

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>等待10秒</title>

</head>

<body>

<form id="form1" runat="server">

<div>

现在剩下 <span id="timeout">10.000</span>秒后将自动跳转</div>

</form>

</body>

</html>

<script type="text/javascript">

function daoshu(){

var djs = document.getElementById("daojishi")

if(djs.innerHTML == 0){

window.location.href='http://blog.163.com/qianw_ok/'

return false

djs.innerHTML = djs.innerHTML - 1

JavaScript一种直译式脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型。它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在HTML(标准通用标记语言下的一个应用)网页上使用,用来给HTML网页增加动态功能。

在1995年时,由Netscape公司的Brendan Eich,在网景导航者浏览器上首次设计实现而成。因为Netscape与Sun合作,Netscape管理层希望它外观看起来像Java,因此取名为JavaScript。但实际上它的语法风格与Self及Scheme较为接近。

为了取得技术优势,微软推出了JScript,CEnvi推出ScriptEase,与JavaScript同样可在浏览器上运行。为了统一规格,因为JavaScript兼容于ECMA标准,因此也称为ECMAScript。

<div id="seconds"></div>

<button id="startBtn">开始</button>

<script>

var maxTime=10,

startTime

function timer(){

var passTime=(new Date().valueOf()-startTime)/1000

if(passTime>=10){

passTime=10

document.getElementById("seconds").innerText="0.00"

}else{

setTimeout(timer,20)

document.getElementById("seconds").innerText=parseInt((maxTime-passTime)*100)/100

}

}

document.getElementById("startBtn").onclick=function(){

passTime=0

startTime=new Date().valueOf()

timer()

}

</script>