关于用javascript实现在页面倒数10秒

来源:百度知道 编辑:UC知道 时间:2024/06/01 21:54:11
不需要触发,直接在页面打开后每秒替换显示 10,9,8,7,6,5,4,3,2,1,0改如何写代码啊??? 别在网上找啊,知道的高手指教下,我是菜鸟~

为什么不在网上找啊?网上这样的代码太多了。

唉,花了二分钟时间帮你写了一个,
将下面的代码另存为一个html文件,然后双击这个html文件就能看到效果:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>10秒</title>
</head>

<body>
<div id=second>10</div>
<script type="text/javascript">
var second=10;
var timer;
function change()
{
second--;

if(second>-1)
{
document.getElementById("second").innerHTML=second;
timer = setTimeout('change()',1000);
}
else
{
clearTimeout(timer);
}
}
timer = setTimeout('change()