<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>发送验证码</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<input type="number">
<button type="button" id="getPhoneCode">获取手机验证码</button>
<script>
$(function(){
$('#getPhoneCode').click(function(){
settime($("#getPhoneCode"),60);
})
});
function settime($obj, time) {
if (time == 0) {
$obj.attr("disabled", false);
/*$obj.css("background", "#f38401").css("cursor", "pointer");*/
$obj.text("获取手机验证码");
return;
} else {
$obj.attr("disabled", true);
/*$obj.css("background", "#ccc").css("cursor", "not-allowed");*/
$obj.text("重新发送(" + time + ")");
time--;
}
setTimeout(function () { settime($obj, time) }, 1000)
}
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>发送验证码</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<input type="number">
<button type="button" id="getPhoneCode">获取手机验证码</button>
<script>
$(function(){
$('#getPhoneCode').click(function(){
settime($("#getPhoneCode"),60);
})
});
function settime($obj, time) {
if (time == 0) {
$obj.attr("disabled", false);
/*$obj.css("background", "#f38401").css("cursor", "pointer");*/
$obj.text("获取手机验证码");
return;
} else {
$obj.attr("disabled", true);
/*$obj.css("background", "#ccc").css("cursor", "not-allowed");*/
$obj.text("重新发送(" + time + ")");
time--;
}
setTimeout(function () { settime($obj, time) }, 1000)
}
</script>
</body>
</html>