<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input type="text"/>
		<button id="btn">点击发送短信</button>
	</body>
</html>
<script>
	var btn = document.getElementById("btn");
	var count = 5; //数据的
	var timer = null ; //定时器的名字
	
	btn.onclick = function(){
		clearInterval(timer); //先清除原先的定时器
		
		this.disabled = true ; //禁用当前的button this一般使用在函数里面,当前值得是button
		
		var that = this //把btn对象给 that
		
		timer = setInterval(sendTextMessage,1000);//开启定时器 定时器的 名字是timer
		
		function sendTextMessage(){
			alert(this);
			alert(that);
			
			count--;
			if(count >= 0){
				that.innerHTML = "还剩余"+count+"秒";
			}else{
				that.innerHTML = "重新发送短信";
				that.disabled = false;
				clearInterval(timer);//清除定时器
				count = 5;
			}
		}
		
	}
</script>
原文:http://www.cnblogs.com/aa-bb/p/6021656.html