我一直试图解决这个问题一天半,我似乎无法弄清楚这种奇怪的行为。
当我这样做时('click'fn),它表现得像双击。好吧,不,这不是真的,如果我在行动时点击它,那么当我再次点击它时,它会关闭第二个动作。不应该单击一次点击点击功能中的所有操作?并尝试了简单的$ .click(fn),但单击一下根本不起作用。
这是我在队列中的代码:
$('#details #map-home').live('click', function(){
var name = $('#dFname').text();
///////////////////////////////////////////////////////////////////
////////// Google Maps API Functions //////////////////////////////
$(this).bind('cbox_complete', function(){
var geocoder;
var map;
var a = $("span#address").text() + $("span#city").text() + $("span#state").text() + $("span#zip").text();
//var image = 'http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag.png';
var div =
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(37.0625, -95.677068);
var myOptions = {
zoom: 19,
center: latlng,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map = new google.maps.Map(document.getElementById("map"), myOptions);
geocoder.geocode( { 'address': a}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var infowindow = new google.maps.InfoWindow({
content: a
});
var marker = new google.maps.Marker({
map: map,
//draggable: true,
//icon: image,
position: results[0].geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, this);
});
infowindow.open(map, marker);
} else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
});
///////////////////////////////////////////////////////////////////
$(this).colorbox({
width:"650",
inline: true,
href:"#map",
overlayClose: false
});
//$('#colorbox').draggable();
return false
});
任何想法?
答案 0 :(得分:0)
我不认为在这里使用live是有道理的,因为你正在处理一个带有id的唯一元素 我将其改为点击。还将绑定移动到单击函数中的cbox_complete 这可能符合预期的行为。还删除了一些奇怪的代码。试试下面的内容。
$("#map-home").bind('cbox_complete', function(){
var geocoder;
var map;
var a = $("span#address").text() + $("span#city").text() + $("span#state").text() + $("span#zip").text();
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(37.0625, -95.677068);
var myOptions = {
zoom: 19,
center: latlng,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map = new google.maps.Map(document.getElementById("map"), myOptions);
geocoder.geocode( { 'address': a}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var infowindow = new google.maps.InfoWindow({
content: a
});
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, this);
});
infowindow.open(map, marker);
} else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
});
$("#map-home").click(function(){
$(this).colorbox({
width:"650",
inline: true,
href:"#map",
overlayClose: false
});
});