小编are*_*s05的帖子

在javascript/jquery中停止执行函数

是否可以通过单击按钮或任何其他事件来停止javascript中的函数执行?以下是我的困境

function drop() {

    setTimeout(function () {    //  call a 250ms setTimeout when the loop is called
       setMarkers(map, locationArray, locationNameArray, iterator);
       iterator++;
       if (iterator < locationArray.length) {      //  if the counter < 10, loop!
         drop();             
       }
     }, 250);
}
Run Code Online (Sandbox Code Playgroud)

此功能以250毫秒的间隔删除画布上的Google地图图钉.现在,如果用户想要导航到上一个屏幕(远离Map页面),单击后退按钮我想停止执行此drop()函数,重置计数器(迭代器)并返回.

知道如何做到这一点,或者它是否可能?谢谢!

javascript jquery function callback setinterval

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

callback ×1

function ×1

javascript ×1

jquery ×1

setinterval ×1