我怎样才能实现setInterval或setTimeout点击按钮。我的代码低吼不循环,我怎么能停止它的第二次按下按钮?连续按钮onClick按钮
<!DOCTYPE HTML>
<html>
<head>
<script>
i=0;
function cycle(){
setInterval(animate(),2000);
}
function animate(){
alert("task");
console.log(i++);
}
</script>
<style>
#paper{
background: #A3C45E;
width:200px;
height:300px;
}
</style>
</head>
<body>
<input type="button" onClick="cycle()" value="Cycle">
<div id="paper"></div>
</body>
</html>
* 编辑,而不使用jQuery
哦,我就是在那里出了问题:)感谢很多gdoron –
@DanielEuchar。我添加了一个演示。祝你好运! – gdoron
真的不知道它已接受答案:) –