onclick点击停止js函数执行 20
请教一下,想让onclick点击后停止执行tran(),方法函数该如何写?<divid='time'></div><buttononclick="stop()"></bu...
请教一下,想让onclick点击后停止执行tran(),方法函数该如何写?
<div id='time'></div>
<button onclick="stop()"></button>
<script type="text/javascript">
var a = 0;
function tran(){
var time = document.getElementById('time');
time.innerHTML = a++;
window.setTimeout('tran()',1000);
}
window.setTimeout('tran()',1000);
</script> 展开
<div id='time'></div>
<button onclick="stop()"></button>
<script type="text/javascript">
var a = 0;
function tran(){
var time = document.getElementById('time');
time.innerHTML = a++;
window.setTimeout('tran()',1000);
}
window.setTimeout('tran()',1000);
</script> 展开
展开全部
<div id='time'></div>
<button onclick="stop()"></button>
<script type="text/javascript">
var a = 0;
function tran(){
var time = document.getElementById('time');
time.innerHTML = a++;
t = window.setTimeout('tran()',1000);
}
function stop(){
clearTimeout(t);
}
var t = window.setTimeout('tran()',1000);
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询