怎么用js 写个程序 时间倒退的代码 显示在页面 进入页面显示 02:00 然后一秒一秒的减少

JavaScript010

怎么用js 写个程序 时间倒退的代码 显示在页面 进入页面显示 02:00 然后一秒一秒的减少,第1张

两分钟倒计时,下面是代码

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

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

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>120秒倒计时</title>

<style>

div{float:leftmargin:3pxwidth:30pxheight:20pxbackground:#CCCtext-align:centerfont-size:12pxline-height:20px}

</style>

<script type="text/javascript">

function oDouble(num)

{

if(num<10)

{

return '0'+num

}

else

{

return num

}

}

window.onload=function()

{

var aDiv=document.getElementsByTagName('div')

var aP=document.getElementsByTagName('p')[0]

var i=120

function times()

{

var oPoints=i / 60

var oSeconds=i % 60

if(i>=0)

{

aDiv[0].innerHTML=oDouble(parseInt(oPoints))

aDiv[2].innerHTML=oDouble(oSeconds)

}

i--

}

setInterval(times,1000)

times()

}

</script>

</head>

<body>

<div></div><div>分</div><div></div><div>秒</div>

<p> </p>

</body>

</html>

前进: history.forward()=history.go(1)\x0d\x0a后退: history.back()=history.go(-1)\x0d\x0a注意事项:前进后退按钮是需要在特定环境下才有效果的,即你需要从另一个页面进入到这个页面后,点击这个后退按钮才有后退的效果,否则是没有的。\x0d\x0a【拓展资料】\x0d\x0ajavascript中的后退和刷新;\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a 后退+刷新在C# Web程序中,如为页面按钮写返回上一页代码\x0d\x0athis.RegisterClientScriptBlock("E", "history.go(-2)")\x0d\x0a其中,history.go(-2),要写为-2,因在按钮事件触发前,已刷新一次页面,所以应是-2。\x0d\x0aResponse.Write("history.go(-2)")\x0d\x0a此处也要写为“-2”。跟直接写脚本的有所不同。history.back()是会上一页\x0d\x0ai=1\x0d\x0ahistory.go(i)去指定的某页\x0d\x0a如果是history.go(0)那就是刷新这两个属于JS代码,相当于IE的前进、后退功能。\x0d\x0a具体的用处就要看什么时候需要这个就用上。比如用户注册时的验证是后台验证,不符合要求的时候就可以用这个,可以最大限度保证用户少重复输入数据。\x0d\x0a例如:载入页面:\x0d\x0afunction onLoadPage(){\x0d\x0aif(event.srcElement.tagName=="SPAN"){\x0d\x0aoFrame=top.window.middle.frames[2]\x0d\x0aoTxt=event.srcElement.innerText\x0d\x0aswitch(oTxt){\x0d\x0acase "前 进":\x0d\x0aoFrame.history.go(1)\x0d\x0acase "后 退":\x0d\x0aoFrame.history.back()\x0d\x0acase "刷 新":\x0d\x0aoFrame.location.reload()\x0d\x0a}\x0d\x0a}\x0d\x0a}\x0d\x0a\x0d\x0a打开一个jsp页面,肯定是用客户端脚本进行刷新了。\x0d\x0aJavascript刷新页面的几种方法:\x0d\x0a1 history.go(0)\x0d\x0a2 location.reload()\x0d\x0a3 location=location\x0d\x0a4 location.assign(location)\x0d\x0a5 document.execCommand('Refresh')\x0d\x0a6 window.navigate(location)\x0d\x0a7 location.replace(location)\x0d\x0a8 document.URL=location.href