function get_mobile_code(){ $.post('sms.jsp', {mobile:jQuery.trim($('#mobile').val())}, function(msg) { alert(jQuery.trim(unescape(msg))); if(msg=='提交成功'){ RemainTime(); } }); }; //倒计时var iTime = 59; var Account; function RemainTime(){ document.getElementById("zphone").disabled = true; var iSecond="",sSecond="",sTime=""; if (iTime >= 0){ iSecond = parseInt(iTime%60); iMinute = parseInt(iTime/60); if (iSecond >= 0){ if(iMinute>0){ sSecond = iMinute + "分" + iSecond + "秒"; }else{ sSecond = iSecond + "秒"; } } sTime=sSecond; if(iTime==0){ clearTimeout(Account); sTime="获取验证码"; iTime = 59; document.getElementById("zphone").disabled = false; }else{ Account = setTimeout("RemainTime()",1000); iTime=iTime-1; } }else{ sTime="没有倒计时"; } document.getElementById("zphone").value = sTime; }
2 回答
qq_梦再美终究是虚幻_03653762
TA贡献1条经验 获得超0个赞
var ret = (endTime.getHours()*3600-curTime.getHours()*3600)+(endTime.getMinutes()*60-curTime.getMinutes()*60)+
(endTime.getSeconds()-curTime.getSeconds());
将计算时间那里该一下就可以了
陈士愚
TA贡献44条经验 获得超44个赞
将post以外的内容放到HTML中运行,可以倒计时。
倒计时代码没问题,那就应该是没有启动起来,断点调试一下你的post请求,看看返回值,以及
if(msg=='提交成功'){
RemainTime();
}
这段代码里到底有没有走到if里面。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>css样式</title> </head> <body> <div id='div1'> <input type="text" name="zphone" id="zphone"> </div> <script> var iTime = 59; var Account; function RemainTime() { document.getElementById("zphone").disabled = true; var iSecond = "", sSecond = "", sTime = ""; if (iTime >= 0) { iSecond = parseInt(iTime % 60); iMinute = parseInt(iTime / 60); if (iSecond >= 0) { if (iMinute > 0) { sSecond = iMinute + "分" + iSecond + "秒"; } else { sSecond = iSecond + "秒"; } } sTime = sSecond; if (iTime == 0) { clearTimeout(Account); sTime = "获取验证码"; iTime = 59; document.getElementById("zphone").disabled = false; } else { Account = setTimeout("RemainTime()", 1000); iTime = iTime - 1; } } else { sTime = "没有倒计时"; } document.getElementById("zphone").value = sTime; } RemainTime(); </script> </body> </html>
添加回答
举报
0/150
提交
取消