clearInterval 函数无法运行问题!麻烦大家看看给详细讲解下!
<!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/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var i;
//一秒后运行函数clock
i=setInterval("clock()",1000);
//隐藏开始按钮
var staClock=document.getElementById("a");
var stpClock=document.getElementById("b");
staClock.style.display="none";
//clock函数
function clock()
{
var myDate=new Date();
var atTime=myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds();
document.getElementById("clock").value=atTime;
}
//停止时间 隐藏停止按钮并显示开始按钮
function stopClock()
{
clearInterval(i);
staClock.style.display="block";
stpClock.style.display="none";
}
//开始时间 隐藏开始按钮并显示暂停按钮
function startClock()
{
i=setInterval(i);
staClock.style.display="none";
stpClock.style.display="block";
}
</script>
</head>
<body>
<input type="text" id="clock" size="6px" />
<input id="b" type="button" value="暂停" onclick="stopClock()" />
<input id="a" type="button" value="开始" onclick="clockStart()" />
</body>
</html>