DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> javascript定時器完整實例
javascript定時器完整實例
編輯:JavaScript綜合知識     

 這篇文章主要介紹了javascript定時器完整實現方法,以實例形式分析了定時器的嵌套調用技巧,具有一定參考借鑒價值,需要的朋友可以參考下

   

本文實例講述了javascript定時器完整實現方法。分享給大家供大家參考。具體實現方法如下:

 

代碼如下: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>定時器</title>
<script type="text/javascript">
var timer = null;
function begin() {
var date = new Date();
var current_time = date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate() + ' ';
current_time += date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
document.getElementById('current_time').value = current_time;
timer = setTimeout('begin()', 1000);
}
function end() {
clearTimeout(timer); //清除掉定時器對象
}
</script>
</head>
<body>
<input type="text" name="current_time" id="current_time"/><input type="button" value="開始" onclick="begin();">
<input type="button" value="結束" onclick="end();"/><br/>
</body>
</html>

 

希望本文所述對大家的javascript程序設計有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved