Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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 将参数传递到google.maps.event.addListener中的回调函数_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 将参数传递到google.maps.event.addListener中的回调函数

Javascript 将参数传递到google.maps.event.addListener中的回调函数,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我试图在google.maps.event.addListener中传递参数 我知道我可以这样做 google.maps.event.addListener(marker, 'mouseover', function() { callback(param1, param2); }); 但是,由于我在循环中声明标记,因此会出现linting错误: 不要在循环中生成函数 我试着这样添加它们: google.maps.event.addListener(country, 'mouseover

我试图在
google.maps.event.addListener中传递参数

我知道我可以这样做

google.maps.event.addListener(marker, 'mouseover', function() {
    callback(param1, param2);
});
但是,由于我在循环中声明标记,因此会出现linting错误:

不要在循环中生成函数

我试着这样添加它们:

google.maps.event.addListener(country, 'mouseover', toggleOpacity, param1, param2);
但它不起作用


有人知道我如何在不使用第二个函数的情况下传递参数吗

我不这么认为。这应该通过向前传递此.id来修复。由于linting,我无法在那里添加函数(){}……那么您的第二次尝试
google.maps.event.addListener(country,'mouseover',toggleOpacity,param1,param2)
不起作用,因为它执行函数并将返回值用作函数指针,指向调用mouseover事件的函数。的可能重复项