您的位置:首页 > Web前端 > JQuery

Jquery 定时器

2014-01-06 15:55 176 查看
<head runat="server">

<title></title>

<script src="Js/jquery-1.10.2.min.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function() {

});

var interval;

function fInterval() {

var currTime = (new Date()).valueOf();

var diftime = currTime - parseInt($("#AcceptTime").val(), 10);

if (diftime < 5 * 1000) {

//隐藏按钮

$("#GetMsg").attr("style", "display:none");

$("#timeTip").attr("style", "display:block");

$("#timeTip").html("请在" + Math.floor((5 * 1000 - diftime) / 1000) + "秒后重新获取验证码!");

return;

}

else {

if (interval != null) {

clearInterval(interval);

}

$("#GetMsg").attr("style", "display:block");

$("#timeTip").attr("style", "display:none");

}

}

function SentCaptcha() {

$("#AcceptTime").val((new Date()).valueOf());

interval = setInterval(fInterval, 1000);

}

</script>

</head>

<body>

<div>

<input type="button" id="GetMsg" value="获取验证码" onclick="SentCaptcha()" style="display:block;" />

<div id="timeTip" style="display: none;"> </div>

<input type="hidden" id="AcceptTime" />

</div>

</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: