<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">
<title>RunJS</title>
</head>
<body>
<input value="秒杀" type="button" id="btnTest"/>
<script type="text/javascript">
var btnTest=document.getElementById("btnTest")
var timerId,temp,timerNum
if(!!btnTest)
{
temp=0,timerNum=0
btnTest.onclick=function(e)
{
temp++
if(!timerId)
{
timerId=setInterval(function(){timerNum++btnTest.value=timerNum+"秒内点击"+temp+"次"},1000)
setTimeout(function(){if(temp<10){reset()}},6000)
}
else if(temp>9 &&timerNum<=5)
{
btnTest.disabled=true
reset()
alert("您点击的太猛了,会吧电脑累坏的,休息3秒吧!")
setTimeout(function(){btnTest.disabled=false},3000)
return false
}
else if(temp<9 &&timerNum==5)
{
reset()
}
}
}
var reset=function(){
clearInterval(timerId)
timerId=null
temp=0
timerNum=0
btnTest.value="秒杀"
}
</script>
</body>
</html>
var count=0//声明全局变量function myprint(){
count++//计数
//其它逻辑
}