<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>js定时器</title>
</head>
<script type="text/javascript">
var int=self.setInterval("clock()",1000); //定义定时器,每一秒钟执行一次
function clock() {
var d =new Date().getSeconds();
document.getElementById("id1").value=d.toString();
}
</script>
<body>
<input type="text" id="id1">
<button onclick="int=window.clearInterval(int)">停止</button>
</body>
</html>