javascript定时器完整实例
网络编程 2021-07-04 21:47www.168986.cn编程入门
这篇文章主要介绍了javascript定时器完整实现方法,以实例形式分析了定时器的嵌套调用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了javascript定时器完整实现方法。分享给大家供大家参考。具体实现方法如下:
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://.w3./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>
<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程序设计有所帮助。
上一篇:JavaScript判断浏览器类型的方法
下一篇:jQuery搜索子元素的方法
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程