我有一个谷歌地图javascript 的工作部分,我确实有一个问题.
现在我遇到的问题是只有一个信息显示,最后一个信息显示.我找到了另一个堆栈线程的解决方案.但我无法弄清楚原因.我对Javascript很新,所以我希望有人可以向我解释改变了什么以及如何改变.
这是工作代码:
function setMarkers(map, locations){
for(var i = 0; i < locations.length; i++){
var marker = locations[i];
var latLng = new google.maps.LatLng(locations[i][1], locations[i][2]);
var content = locations[i][0];
var infowindow = new google.maps.InfoWindow();
marker = new google.maps.Marker({
position:latLng,
map: map
});
google.maps.event.addListener(marker, 'click', function(content){
return function(){
infowindow.setContent(content);
infowindow.open(map, this);
}
}(content));
}
}
Run Code Online (Sandbox Code Playgroud)
这是原始的破解代码(我只会粘贴更改的代码):
google.maps.event.addListener(marker, 'click', function(){
infowindow.setContent(content);
infowindow.open(map, marker);
});
Run Code Online (Sandbox Code Playgroud)
现在,如果你这么善良,我想知道的是:
返回fn服务的功能是什么,以及
什么是最后添加(content),addListener (}(content));)因为据我所知,内容已经在setContent属性中设置.
谢谢!
所以我正处于尝试制作一些验证码作为练习的早期阶段。
到目前为止,我的图像生成代码:
session_start();
header('Content-type: image/jpeg');
$string = $_SESSION['secure'];
$font_size = 5;
$image_width = ImageFontWidth($font_size)*strlen($string);
$image_height = ImageFontHeight($font_size);
$image = imagecreate($image_width, $image_height);
imagecolorallocate($image, 255, 255, 255);
$font_colour = imagecolorallocate($image, 0, 0, 0);
imagestring($image, $font_size, 0, 0, $string, $font_colour);
imagejpeg($image);
Run Code Online (Sandbox Code Playgroud)
以及表单本身的代码(函数位于单独的文件(rand.php)中):
function random_string($length = 10){
$alphnum = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$alphnum_length = strlen($alphnum);
$random_string = '';
for ($i=0; $i < $length; $i++) {
$random_string.= $alphnum[rand(0, $alphnum_length)];
}
return $random_string;
}
require('../rand.php');
$_SESSION['secure'] = random_string(5);
echo $_SESSION['secure'];
Run Code Online (Sandbox Code Playgroud)
现在它生成了一个随机字符串,并且在生成图像页面上确实生成了图像。我还没有开始在表单页面上输出图像,但这不是问题。
问题是每刷新 20 次左右的表单页面(当前仅输出 random_string 的页面)就会收到一条错误消息:
( ! …