猿问

怎样让两个定时器不互相影响?

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>无标题文档</title>

</head>


<body>

<input class="code" onClick="TestGetCode(this)" value="获取验证码" type="button"/>

<br>

<input class="code" onClick="TestGetCode(this)" value="获取验证码" type="button"/>

<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>

<script type="text/javascript">

//获取短信验证码

var t=60;

function TestGetCode(i){

   if(t==0){

        i.removeClass("grey-bg");

        i.removeAttribute("disabled");

        i.value="获取短信验证码";

        t=60;

    }else{

        i.setAttribute("disabled", true); 

        i.value="重新发送(" + t + ")"; 

        t--;

        $(this).addClass("grey-bg");

        setTimeout(function(){TestGetCode(i)},1000);

    }

}

</script>

</body>

</html>

点击其中一个还好,两个都点就出问题了

慕无忌1623718
浏览 1017回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答