<input type="text" id="key" value="1" /><input type="button" οnclick="doTimer1()" value="执行" />
<input type="button" οnclick="stopCount1()" value="停止" />
<script>
var c1 = 0;var t=0;
var timer_is_on1= 0 ;
function myTimer(){
t=t+1;
console.log(t);
if($("#key").val()=="2")
{
stopCount1();
}
}
function doTimer1(){
if (!timer_is_on1) {
timer_is_on1 = 1;
myt = setInterval(function () {
myTimer()
},1000);
}
}
function stopCount1(){
clearInterval(myt);
timer_is_on1=0;
}
</script>