2、如果你是想代码里面控制
<script>$(function(){ getData() setInterval(function(){ getData() }, 3000)})function getData(){ alert("go ,let us go") }
</script>
3、循环次数的
<script>
$(function(){
var count=0
getData()
setInterval(function(){
getData(100)
}, 3000)
})
function getData(var sum){
if(count>=sum){
return false
}
alert("go ,let us go")
count=count+1
}
<!DOCTYPE HTML><html>
<head>
<title>TestMouse</title>
<meta charset="utf-8"/>
</head>
<style>
body{
background-color: gray
}
.rect{
position: relative
display: block
width: 100px
height: 100px
background-color: red
margin: 0 auto
cursor: pointer
-moz-border-radius: 12px
-webkit-border-radius: 12px
border-radius: 12px
border:3px solid yellow
}
.timeBox{
position: relative
display: block
margin:10px auto
width: 300px
height: 35px
text-align: center
}
</style>
<body>
<div class="rect" id="rect" onclick="setCount()"></div>
<input type="text" class="timeBox" id="timeBox" disabled/>
<script>
/* 主要思路是:
一开始时标签上是有onclick属性的,然后点击之后进入方法,
便把onclick事件移除,且
方法中有setTimeout函数,设置时间的时间到期之后便会执行,
执行的功能就是给标签添加onclick事件,那么点击就会又有效果了
*/
var rect=document.getElementById("rect")
var timer=1
var clickCount=0
var runCount=0
//addEvnetListner有兼容性问题,此处我只针对Mozilla系列
rect.addEventListener("click",function(){clickCount++},false)
function setCount(){
rect.onclick=null
timer=setTimeout(timeOver,2000)
}
function timeOver(){
runCount++
rect.onclick=setCount
document.getElementById("timeBox").value="点击次数:"+clickCount+" ,执行次数:"+runCount
//clearTimeout(timer)
}
</script>
</body>
</html>
以循环10次为例for循环:
for (var i=0i<10i++){}
while循环:
var i = 0
while (true){
i ++
if (i>=10) break
//这里写要执行的语句
}