<input id="mobile" placeholder="请输入验证码" maxlength="6">
<input type="button" id="btn" value="免费获取验证码" />
<script type="text/javascript">
var wait = 30;
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value = "免费获取验证码";
wait = 30;
} else {
o.setAttribute("disabled", true);
o.value = "重新发送(" + wait + ")";
wait--;
setTimeout(function() {
time(o)
}, 1000)
}
}
//document.getElementById("btn").οnclick=function(){time(this);}
$("#btn").on('click', function() {
var mobile = $("#mobile").val();
if (mobile == null || mobile == '') {
alert("验证码不能为空")
} else {
time(this);
}
})
<input type="button" id="btn" value="免费获取验证码" />
<script type="text/javascript">
var wait = 30;
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value = "免费获取验证码";
wait = 30;
} else {
o.setAttribute("disabled", true);
o.value = "重新发送(" + wait + ")";
wait--;
setTimeout(function() {
time(o)
}, 1000)
}
}
//document.getElementById("btn").οnclick=function(){time(this);}
$("#btn").on('click', function() {
var mobile = $("#mobile").val();
if (mobile == null || mobile == '') {
alert("验证码不能为空")
} else {
time(this);
}
})