<!doctype html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var InterValObj; //timer變量,控制時間
var count = 60; //間隔函數,1秒執行
var curCount;//當前剩餘秒數
function sendMessage() {
curCount = count;
//設置button效果,開始計時
$("#btnSendCode").attr("disabled", "true");
$("#btnSendCode").val("請在" + curCount + "秒內輸入驗證碼");
InterValObj = 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 (curCount == 0) {
window.clearInterval(InterValObj);//中止計時器
$("#btnSendCode").removeAttr("disabled");//啓用按鈕
$("#btnSendCode").val("從新發送驗證碼");
}
else {
curCount--;
$("#btnSendCode").val("請在" + curCount + "秒內輸入驗證碼");
}
}
</script>
</head>
<body>
<input id="btnSendCode" type="button" value="發送驗證碼" onclick="sendMessage()" /></p>
</body>
</html>