<strong>第一种方法:</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="32452" class="copybut" id="copybut32452" onclick="doCopy('code32452')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code32452"> <br><%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br><html> <br><head> <br><title>定时器</title> <br><script language="javascript" src="jquery-1.4.2.js"></script> <br><script language="javascript"> <br>//使用setInterval间歇调用 (不建议使用该方法) <br>$(function(){ <br>setInterval(function(){ <br>$("#currentTime").text(new Date().toLocaleString()); <br>},1000); <br>}); <br></script> <br></head> <br><body> <br><div id="currentTime"></div> <br></body> <br></html> <br> </div> <br><strong>第二种方法:</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="24166" class="copybut" id="copybut24166" onclick="doCopy('code24166')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code24166"> <br><%@ page language="java" contentType="text/html; charset=UTF-8" <BR>pageEncoding="UTF-8"%> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br><head> <br><title>定时器</title> <br><script language="javascript" src="jquery-1.4.2.js"></script> <br><script language="javascript"> <br>//使用setTimeout超时调用 <br>function startTime(){ <br>$("#currentTime").text(new Date().toLocaleString()); <br>setTimeout('startTime()',1000); <br>} <br></script> <br></head> <br><body onload="startTime()"> <br><div id="currentTime"></div> <br></body> <br></html> <br> </div> <br><strong>第三种方法:</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="2139" class="copybut" id="copybut2139" onclick="doCopy('code2139')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code2139"> <br><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br><head> <br><title>定时器</title> <br><script type="text/javascript"> <br>var c=0; <br>var t; <br>function timedCount(){ <br>document.getElementById('txt').value=c; <br>c=c 1; <br>t=setTimeout("timedCount()",1000); <br>} <br>function stopCount(){ <br>clearTimeout(t); <br>} <br></script> <br></head> <br><body> <br><form> <br><input type="button" value="开始计时!" onclick="timedCount()"/> <br><input type="text" id="txt"/> <br><input type="button" value="停止计时!" onclick="stopCount()"/> <br></form> <br></body> <br></html> <br> </div>