Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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 当用户单击任何信息窗口中的复选框时,我如何采取行动?_Javascript_Jquery_Html_Css_Google Maps - Fatal编程技术网

Javascript 当用户单击任何信息窗口中的复选框时,我如何采取行动?

Javascript 当用户单击任何信息窗口中的复选框时,我如何采取行动?,javascript,jquery,html,css,google-maps,Javascript,Jquery,Html,Css,Google Maps,我可以让它在正常的网页以下的例子在这个论坛找到工作 但当用户选中或取消选中(单击或更改)25个信息窗口中的任何一个复选框时,尝试采取行动。。。无法找到任何选择器使其工作 完整测试页: // //最新测试代码(基于本论坛的研究) $(文档).ready(函数(){ $('input[type=checkbox]')。单击(函数(){ 如果($(this).is(':checked')){ //警报($(this.attr('id')); 警报(“已检查”); } else{alert(“un

我可以让它在正常的网页以下的例子在这个论坛找到工作

但当用户选中或取消选中(单击或更改)25个信息窗口中的任何一个复选框时,尝试采取行动。。。无法找到任何选择器使其工作

完整测试页:

//
//最新测试代码(基于本论坛的研究)
$(文档).ready(函数(){
$('input[type=checkbox]')。单击(函数(){
如果($(this).is(':checked')){
//警报($(this.attr('id'));
警报(“已检查”);
}   
else{alert(“unchecked”);}
});
});
//
var标记=[];
myLatlng=新的google.maps.LatLng(“-4.293099”,“55.699843”);
var marker=new google.maps.marker(
{图标:'http://mosttraveledpeople.com/beach/beachicon_red32.png',
职位:myLatlng,
地图:地图,
标题:“塞舌尔普拉斯林岛安塞拉齐奥”,
活动:
{
mouseout:function(){infoWindo.close();}
} 
} 
);
var infoWindowContent=“安塞拉齐奥,塞舌尔普拉斯林岛
参观:”; AddInfo窗口(标记,infoWindowContent); 标记器。推(标记器);
它看起来像是加载贴图后需要调用的第一块代码,但在选择器选择任何内容之前调用它(因为它尚未渲染)

现在有了mouseout事件——为什么不为mouseover添加一个事件呢?在该事件上,您可以使用jquery选择器来选中该信息框中的复选框

或者在创建标记后,可以执行以下操作:

  google.maps.event.addListener(marker, 'mouseover', function() {
    $(document).ready(function(){
    $('input[type=checkbox]').click(function(){
      if($(this).is(':checked')){
       // alert($(this).attr('id'));  
          alert ("checked");
     }   
    else {alert("unchecked");}
     });
   });
  });
祝你好运
-Mike

只有在信息窗口打开后,复选框才会附加到DOM。您有两个选择:

  • 使用infowindow中HTML中定义的onclick函数:

    var infoWindowContent = "<table border='0' style='background-color: white'><tr><td><img src='http://media-cdn.tripadvisor.com/media/photo-s/05/76/76/ab/anse-lazio.jpg' height='80'></td><td>Anse Lazio, Praslin Island, Seychelles<br><form id='upbeach6' name='upbeach6' action='#' method='post' onSubmit='return false;'><input type='hidden' name='beachid' value='6'>Visited: <input type='checkbox' name='flag6' id='flag6' value='Y' onclick='alert(\'foo\');'></input></form></td></tr></table?>";
    
    var infoWindowContent=“安塞拉齐奥,塞舌尔普拉斯林岛
    参观:”;
  • 在infowindow附加到DOM之后,在infowindow上的
    domready
    事件侦听器中,使用JQuery添加侦听器

  • 您尝试过另一个版本的jquery吗?例1.11.2请在您的问题中提供答案。是的!非常感谢你。我用你的代码让它工作。现在我需要将其更改为实际执行我需要的ajax更新调用(而不仅仅是alert:-),但如果我被卡住了,这是另一篇文章的内容。。。你太棒了!(我会慢慢地继续学习)
    var infoWindowContent = "<table border='0' style='background-color: white'><tr><td><img src='http://media-cdn.tripadvisor.com/media/photo-s/05/76/76/ab/anse-lazio.jpg' height='80'></td><td>Anse Lazio, Praslin Island, Seychelles<br><form id='upbeach6' name='upbeach6' action='#' method='post' onSubmit='return false;'><input type='hidden' name='beachid' value='6'>Visited: <input type='checkbox' name='flag6' id='flag6' value='Y' onclick='alert(\'foo\');'></input></form></td></tr></table?>";