http://www.jb51.net/article/42505.htm jsp实现方法。
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<script type="text/javascript">
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}
function stopCount()
{
clearTimeout(t)
}
</script>
</head>
<body>
<form>
<input type="button" value="开始计时!" onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="停止计时!" onClick="stopCount()">
</form>
<p>请点击上面的“开始计时”按钮来启动计时器。输入框会一直进行计时,从 0 开始。点击“停止计时”按钮可以终止计时。</p>
<p>timedCount(),1000ms自己调自己。</p>
</body>
</html>
详细出处参考:
http://www.jb51.net/article/42505.htmdocument . getElementById ( )
语法:
oElement = document . getElementById ( sID )
参数:
sID : 必选项。字符串 (String) 。
返回值:
oElement : 对象 (Element) 。
说明:
根据指定的 id 属性值得到对象。返回 id 属性值等于 sID 的第一个对象的引用。假如对应的为一组对象 ,则返回该组对象中的第一个。
如果无符合条件的对象,则返回 null 。
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。
语法:
setTimeout(code,millisec)
