标签:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="yan.aspx.cs" Inherits="Technology.yan" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>短信验证码倒计时</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
var ValObj; //timer变量,控制时间
var count = 60; //间隔函数,1秒执行
var cou;//当前剩余秒数
function sendMsg() {
cou = count;
//设置button效果,开始计时
$("#btn_yzm").attr("disabled", "true");
$("#btn_yzm").val("请在" + cou + "秒内输入验证码");
ValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次
//向后台发送处理数据
$.ajax({
type: "POST", //用POST方式传输
dataType: "text", //数据格式:JSON
url: ‘Login.ashx‘, //短信操作处理程序
data: "dealType=" + dealType + "&uid=" + uid + "&code=" + code,
error: function (XMLHttpRequest, textStatus, errorThrown) { },
success: function (msg) { }
});
}
//timer处理函数
function SetRemainTime() {
if (cou == 0) {
window.clearInterval(ValObj);//停止计时器
$("#btn_yzm").removeAttr("disabled");//启用按钮
$("#btn_yzm").val("重新发送验证码");
}
else {
cou--;
$("#btn_yzm").val("请在" + cou + "秒内输入验证码");
}
}
</script>
</head>
<body>
<input id="btn_yzm" type="button" value="发送验证码" onclick="sendMsg()" />
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/Vincene/p/4560191.html