js之定时器

Posted 贺言

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js之定时器相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定时器</title>

<style>
#id1{
width:150px;
height:20px;
}
</style>
</head>
<body>
<input type="text" id="id1" onclick="begin()">
<button onclick="end()">停止</button>
<script>
function showtime(){
var current=new Date().toLocaleString();
var elem=document.getElementById(\'id1\');
elem.value=current;

}
begin()
var clock
function begin(){
if (clock==undefined)
{ showtime()
clock=setInterval(showtime,1000);
}
}
function end(){
clearInterval(clock)
clock=undefined
}




</script>


</body>
</html>

--------------------------------------------------------------

 

 

 

以上是关于js之定时器的主要内容,如果未能解决你的问题,请参考以下文章

js之定时器

页面刷新之定时刷新(定时器,meta)

js之定时器

js定时器之setTimeout的使用

JS之BOM对象常用知识点整理

js之定时器