javascript手机短信倒计时120s
function countDown(){
var time = $(".e-time strong").text();
$(".e-time strong").text(time - 1);
if (time == 1) {
$(".timeDiv").hide();
$(".sendMobileCode").show();
$(".e-time strong").text(119);
} else {
setTimeout(countDown, 1000);
}
}
或者
var counttimer =120;
var timerset =null;
$('.reg_phone .a1').bind("click",countime);
function countime(){
var mobile = $('#user_phone').val();
var mobileReg = /^1[358][0-9]{9}$/;
if(mobileReg.exec(mobile)){
var params = 'mobile='+mobile;
$.ajax({
url:'/user.php?act=send_pwd_code&is_ajax=true',
data:params,
dataType:'json',
type:'post',
success:function(res){
if(res.error == 1){
PopFn(res.msg);
}else{
$('.reg_phone .a1').html("<span class='cut_timer'>120</span>" + "秒后重新获取").css({"cursor" : "text"});
if($(".cut_timer").length > 0){
timerset = setInterval(function(){
counttimer--;
$(".cut_timer").html(counttimer);
if(counttimer == 0){
clearInterval(timerset);
$('.reg_phone .a1').html("获取短信验证码").css({"cursor" : "pointer"}).bind("click",function(){
countime();
});
counttimer =120;
}
},1000);
};
$('.reg_phone .a1').unbind("click");
}
}
});
}else{
PopFn('请输入手机号码');
}
};
function timeshow(obj,second, link){
setTimeout(fun, 1000);
var funTime =second;
function fun(){
funTime--;
$(obj).html(funTime)
if (funTime == 1){
if(link){
window.location.href = link;
}else{
window.location.href = "/";
}
}else{
setTimeout(fun, 1000);
}
}
}