<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var timer;//聲明一個定時器
var count = 0;
function test()
{
//每隔500毫秒執行一次add()方法
timer = window.setInterval("add()",500);
}
function add(){
alert(++ count);
if (count == 5)
{
//若是count值達到5,清空定時器
window.clearInterval(timer);
}
}
</SCRIPT>
</head>
<input type="button" value="點擊" onclick="test()">
</html>html