首页 > 代码库 > 计时器应用

计时器应用

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>计时器</title>
</head>
<body>
	<button id="setTime">免费发送短信</button>
	<script type="text/javascript" src="http://www.mamicode.com/jquery.min.js"></script>
	<script type="text/javascript">
		var time=10;
		$(document).ready(function(){
			$("#setTime").click(function(){
				$(this).attr("disabled","disabled");
				var span="秒后免费发送短信";
				$(this).html(time+span);
				var t=setInterval(function(){
					time=time-1;
					if(time==0){
						$("#setTime").html("免费发送短信");
						$("#setTime").removeAttr("disabled");
						time=10;
						clearInterval(t);
					}else{
						$("#setTime").html(time+span);
					}
				},1000)
			})
		})
		
	</script>
</body>
</html>


计时器应用