1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> 6 <title>传递事件参数</title> 7 <style type="text/css"> 8 *{ 9 margin:0px; 10 padding:0px; 11 } 12 body, button, input, select, textarea { 13 font: 12px/16px Verdana, Helvetica, Arial, sans-serif; 14 } 15 p{ 16 603px; 17 padding-top:3px; 18 overflow:hidden; 19 } 20 #container{ 21 min-600px; 22 min-height:767px; 23 } 24 </style> 25 <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp"></script> 26 <script> 27 function init() { 28 var map = new qq.maps.Map(document.getElementById("container"),{ 29 center: new qq.maps.LatLng(39.916527,116.397128), 30 zoom: 13 31 }); 32 //添加监听事件 获取鼠标单击事件 33 qq.maps.event.addListener(map, 'click', function(event) { 34 var marker=new qq.maps.Marker({ 35 position:event.latLng, 36 map:map 37 }); 38 //添加到提示窗 39 var info = new qq.maps.InfoWindow({ 40 map: map 41 }); 42 //获取标记的点击事件 43 qq.maps.event.addListener(marker, 'click', function() { 44 info.open(); 45 info.setContent('<div style="text-align:center;white-space:nowrap;'+ 46 'margin:10px;">单击标记</div>'); 47 info.setPosition(new qq.maps.LatLng(event.latLng.getLat(),event.latLng.getLng())); 48 }); 49 qq.maps.event.addListener(map, 'click', function(event) { 50 marker.setMap(null); 51 info.close(); 52 }); 53 }); 54 } 55 </script> 56 </head> 57 <body onload="init()"> 58 <div id="container"></div> 59 <p>给地图绑定了点击事件,当点击地图时,会在点击位置显示Marker。</p> 60 </body> 61 </html>