javascript - 问问这个怎么清除清定时器

查看:99
本文介绍了javascript - 问问这个怎么清除清定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

请问如何清除这个定时器:

div {width:100px;height:100px;background-color:green;}
input {margin-top:10px;}

<div></div>
<input type = "button" value = "点我开始">
<input type = "button" value = "拜拜">

$("input:eq(0)").click(function(){
var a = setInterval(round,1000);

})
function round(){
$("div").animate(

   {
   width:"300px",
   height:"300px"
   },2000)

$("div").animate(

   {
   width:"100px",
   height:"100px"
   },2000)

}

解决方案

你那个a变量要放到外面,放在回调里,以后要清时就访问不到了。。。

清的时候需要 clearInterval(a)

这篇关于javascript - 问问这个怎么清除清定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆