开始和结束时钟练习

<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function()
{
var i=0;
function auto()
{
i++;
alert(i);
}

var timer=null;
document.getElementsByTagName("button")[0].onclick=function()
{
timer=setInterval(auto,2000);
};
document.getElementsByTagName("button")[1].onclick=function()
{
clearInterval(timer);
};



}
</script>
</head>

<body>
<button>开始定时机</button>
<button>结束定时机</button>
</body>
</html>

原文地址:https://www.cnblogs.com/ll-taj/p/5251016.html