第一種方法
<%@ page language="java" contentType="text/html; charset=UTF
<!DOCTYPE html PUBLIC "
<html>
<head>
<title>定時器</title>
<script language="javascript" src="jquery
<script language="javascript">
//使用setInterval間歇調用 (不建議使用該方法)
$(function(){
setInterval(function(){
$("#currentTime")
}
});
</script>
</head>
<body>
<div id="currentTime"></div>
</body>
</html>
第二種方法
<%@ page language="java" contentType="text/html; charset=UTF
pageEncoding="UTF
<!DOCTYPE html PUBLIC "
<head>
<title>定時器</title>
<script language="javascript" src="jquery
<script language="javascript">
//使用setTimeout超時調用
function startTime(){
$("#currentTime")
setTimeout(
}
</script>
</head>
<body onload="startTime()">
<div id="currentTime"></div>
</body>
</html>
第三種方法
<%@ page language="java" contentType="text/html; charset=UTF
<!DOCTYPE html PUBLIC "
<head>
<title>定時器</title>
<script type="text/javascript">
var c=
var t;
function timedCount(){
document
c=c+
t=setTimeout("timedCount()"
}
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>
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19962.html