[英]How to open jQuery UI dialog box on Google Maps click
I am using the following code to show a jQuery UI dialog when the mouse is clicked on the map: 当在地图上单击鼠标时,我正在使用以下代码来显示jQuery UI对话框:
GEvent.addListener(map, "click", clicked);
function clicked(overlay, latlng) {
$('#dialog').show();
};
Both clicked function and show() function works fine on their own but when I want to open dialog box by clicking on the map it does not. 单击的函数和show()函数本身都可以正常工作,但是当我想通过单击地图打开对话框时,效果却不佳。 Any ideas?
有任何想法吗?
You may want to check out the following example: 您可能想查看以下示例:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps jQuery UI Demo</title>
<link type="text/css" href="themes/base/jquery.ui.all.css" rel="stylesheet" />
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false"
type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"
type="text/javascript"></script>
<script src="jquery-ui-1.8.custom.min.js" type="text/javascript"></script>
</head>
<body onunload="GUnload()">
<div id="map" style="width: 450px; height: 300px"></div>
<div id="dialog" title="Basic Dialog" style="display: none;">Dialog</div>
<script type="text/javascript">
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
GEvent.addListener(map, "click", function(overlay, latlng) {
$('#dialog').dialog();
});
</script>
</body>
</html>
Screenshot: 屏幕截图:
alt text http://img517.imageshack.us/img517/643/jquerygoogle.png 替代文字http://img517.imageshack.us/img517/643/jquerygoogle.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.