在javascript中停止setInterval

MIR*_*MIX -1 javascript button setinterval

我有一个模拟热图的按钮.当按钮点亮时,我使用setInterval函数

 <button onclick="setInterval(function(){update_map()},50);">simulate</button>
Run Code Online (Sandbox Code Playgroud)

我的功能如下:

function update_map(){
  counter+=50;
  var i =1
  for(i=counter-50;i<<?php echo json_encode($lat); ?>.length & i<counter;i++){
  taxiData.push(new google.maps.LatLng(<?php echo json_encode($lat); ?>[i],<?php echo json_encode($log); ?>[i]));
 }
  var pointArray = new google.maps.MVCArray(taxiData);
heatmap = new google.maps.visualization.HeatmapLayer({
    data: pointArray
  });

  heatmap.setMap(map);
  if(i==<?php echo json_encode($lat); ?>.length )
  clearInterval(setInterval(function(){update_map()},50));
}
Run Code Online (Sandbox Code Playgroud)

任何形式的帮助或建议将不胜感激.

pat*_*ter 5

很简单.将间隔设置为变量然后清除它.

var refreshIntervalId = setInterval(fname, 10000);

/* later */
clearInterval(refreshIntervalId);
Run Code Online (Sandbox Code Playgroud)

在JavaScript中停止setInterval调用