Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
传单javascript-如何清除标记上的setTimeout?_Javascript_Jquery_Settimeout_Leaflet_Cleartimeout - Fatal编程技术网

传单javascript-如何清除标记上的setTimeout?

传单javascript-如何清除标记上的setTimeout?,javascript,jquery,settimeout,leaflet,cleartimeout,Javascript,Jquery,Settimeout,Leaflet,Cleartimeout,我正在将这样的标记添加到地图中: map.addLayer(l), setTimeout(function() { map.removeLayer(l) }, 1e4), 10秒后,每个标记再次移除。现在我想实现这一点,当用户在这10秒内点击一个标记时,市场在地图上保持可见。到目前为止,我已经: l.on('click', function(e) { console.log(e); console.log(e.layer._leaflet_id); console.log(l

我正在将这样的标记添加到地图中:

 map.addLayer(l), setTimeout(function() {
      map.removeLayer(l)
 }, 1e4),
10秒后,每个标记再次移除。现在我想实现这一点,当用户在这10秒内点击一个标记时,市场在地图上保持可见。到目前为止,我已经:

l.on('click', function(e) {

console.log(e);
console.log(e.layer._leaflet_id);
console.log(l);

clearTimeout(e.layer._leaflet_id);

});

但它现在确实起作用了。你知道我如何实现这一点吗?

你需要使用相关ID调用clearTimeout来取消设置超时

    var myVar;
    timeout_init();

    function timeout_init() {
        myVar = setTimeout(function(){
            $('.marker').hide();
            },5000);
    }

$( ".marker" ).click(function() {
    clearTimeout(myVar);
});

setTimeout
返回一个ID。您需要使用该ID调用
clearTimeout
。@MikeC-我尝试通过调用clearTimeout(例如,layer.\u传单\u ID)来实现这一点;它具有setTimeout函数(l)的id。我还尝试了其他一切,但那些标记正在消失:(你确定要将其保存到
\u传单\u id
?代码的顶部似乎没有表明这一点。