使用js函数实现按钮控制倒计时

1.设置控制倒计时的函数

function count(){
    var count = 149;//倒计时开始的秒数
    var countdown = setInterval(CountDown, 1000); //倒计时增量(1000为毫秒)
    function CountDown() {
	    $("#sendPhoneCode").val("(" + count + ")重新发送");//重写按钮值 
		    if (count == 0) {
			    $("#sendPhoneCode").val("重新发送").removeAttr("disabled"); //计时结束,按钮可用
			    $("#sendPhoneCode").css("backgroundColor","#63B8FF");
			    clearInterval(countdown); //清除定时函数
		    } 
		    count--; 
    } 
}

2.设置调用该倒计时函数的函数

function click(){
    $("#sendPhoneCode").attr("disabled", true);
	$("#sendPhoneCode").css("backgroundColor","#ccc");
    count();
}

猜你喜欢

转载自blog.csdn.net/Java_Long_Asus/article/details/81776966