JavaScript timer ON OFF

<html>
<head>
<meta charset="utf-8">
<title>JS定时器</title>
<style type="text/css">
    #btn1:hover,#btn2:hover {
        background: red;
    }
</style>
</head>

<body>
<input type="button" id="btn1" value="开启" />
<input type="button" id="btn2" value="关闭" />
<script>
    var obtn1=document.getElementById('btn1');
    var obtn2=document.getElementById('btn2');
    var timer=null;
    obtn1.onclick=function() {
        timer=setInterval(function()   // Open loop: appears once per second balloon 
        { 
            Alert ( 'A' ); 
        }, 2000 ); 
    } 
    obtn2.onclick = function () { 
        the clearInterval (Timer);         // close the loop 
    }
 </ Script> 
</ body > 
</ HTML>

 

Guess you like

Origin www.cnblogs.com/hxun/p/11103026.html