<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>倒计时</title>
<script src="jquery.js"></script>
<script type="text/javascript">
//定义初始化的变量
var item =59;
//定义函数实现定时器效果
function getTime(){
//判断item值
if(item==0){
//清除定时器
clearTimeout(act);
$(‘#set‘).val(‘再次获得验证码‘).attr(‘disabled‘,false);
item=59;
}else{
act = setTimeout("getTime()",1000);
$(‘#set‘).val(‘还剩‘+item+‘s秒‘);
item = item-1;
}
}
$(function(){
$(‘#set‘).click(function(){
getTime();
});
});
</script>
</head>
<body>
<input type="button" value="点击获取验证码" id="set"/>
</body>
</html>
时间: 2024-10-16 17:56:32