求js高手,给短信验证码js添加一个倒计时功能 20
functioncheckMobile(){varsMobile=document.mobileform.mobile.valueif(!(/^1[3|5][0-9]\d...
function checkMobile(){
var sMobile = document.mobileform.mobile.value
if(!(/^1[3|5][0-9]\d{4,8}$/.test(sMobile))){
alert("请输入正确的手机号码");
document.mobileform.mobile.focus();
return false;
}
<form action="" name="mobileform" method="post" onSubmit="return checkMobile();">
<INPUT name="mobile" class=tdc size="40" maxLength="11">
<INPUT name="action" type="hidden" value=mobile> <INPUT id=btn class=bdtj name=B1 type=submit value=查询 >
</FORM>
当用户输入正确的手机号码之后,按钮变成60秒的倒计时,求高手帮实现。 展开
var sMobile = document.mobileform.mobile.value
if(!(/^1[3|5][0-9]\d{4,8}$/.test(sMobile))){
alert("请输入正确的手机号码");
document.mobileform.mobile.focus();
return false;
}
<form action="" name="mobileform" method="post" onSubmit="return checkMobile();">
<INPUT name="mobile" class=tdc size="40" maxLength="11">
<INPUT name="action" type="hidden" value=mobile> <INPUT id=btn class=bdtj name=B1 type=submit value=查询 >
</FORM>
当用户输入正确的手机号码之后,按钮变成60秒的倒计时,求高手帮实现。 展开
1个回答
2015-11-30
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>pro.html</title>
<style type="text/css">
.checkCode {
cursor: pointer;
border: 1px solid black;
text-align: center;
line-height: 26px;
width: 115px;
height: 35px;
}
</style>
<script type="text/javascript">
var sleep = 30, interval = null;
window.onload = function ()
{
var btn = document.getElementById ('btn');
btn.onclick = function ()
{
if (!interval)
{
this.style.backgroundColor = 'rgb(243, 182, 182)';
this.disabled = "disabled";
this.style.cursor = "wait";
this.value = "重新发送 (" + sleep-- + ")";
interval = setInterval (function ()
{
if (sleep == 0)
{
if (!!interval)
{
clearInterval (interval);
interval = null;
sleep = 30;
btn.style.cursor = "pointer";
btn.removeAttribute ('disabled');
btn.value = "免费获取验证码";
btn.style.backgroundColor = '';
}
return false;
}
btn.value = "重新发送 (" + sleep-- + ")";
}, 1000);
}
}
}
</script>
</head>
<body>
<input class="checkCode" type="button" id="btn" value="免费获取验证码" />
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询