2010-06-14 5 views
1

포커스가 noteTitle로 설정되지 않는 이유는 무엇입니까?infoWindow에서 입력 필드에 포커스를 설정할 수 없습니다.

Google지도 API V3을 사용하고 있습니다.

getNoteForm()은 "noteTitle"입력 필드를 리턴합니다.

$ ("# noteTitle") .focus()는 방화 광에서 실행하면 잘 작동합니다.

나는지도를 클릭 할 때이 함수를 호출하면 이벤트 리스너를 추가하기 전에 정보창을 여는처럼

function setNewNoteInfowindow(latlng) { 
if (geocoder) { 
     geocoder.geocode({'latLng': latlng}, function(results, status) { 
    var address = ""; 

    if (status == google.maps.GeocoderStatus.OK) { 
    if (results[1]) { 
    address = results[1].formatted_address; 
      } 
     } 

    newNoteInfowindow = new google.maps.InfoWindow({ 
    content: getNoteForm(latlng, address), 
     size: new google.maps.Size(40,50) 
    }); 

    newNoteInfowindow.open(map, newNoteMarker); 

    google.maps.event.addListener(newNoteInfowindow, 'domready', function() { 
      $("#noteTitle").focus(); 
     }); 

    google.maps.event.addListener(newNoteInfowindow, 'closeclick', function() { 
      newNoteMarker.setVisible(false); 
     }); 
    }); 
} 
} 
+0

다른 곳에 $ ("# noteTitle"). focus(); 문을 옮겨 보았습니까? 아마 $ (document) .ready로 시작해도 될까요? – HurnsMobile

+0

예, 행운을 보냅니다. – thomas

+0

이벤트가 올바르게 발생했는지 확인 했습니까? 'alert ('something');을 추가하여 실행 여부를 확인하십시오. –

답변

1

것 같습니다. 따라서 리스너를 추가 할 때 이미 이벤트가 발생했습니다. open() 및 addListener()의 순서를 반대로 시도해보십시오.

google.maps.event.addListener(newNoteInfowindow, 'domready', function() { 
      $("#noteTitle").focus(); 
     }); 

    newNoteInfowindow.open(map, newNoteMarker); 
+0

네, 저도 시도했습니다 ... 행운을 빈다. – thomas

+2

이렇게 처리했습니다. 예쁘지는 않지만 작동합니다. google.maps.event.addListener (map, 'click', function (event) { \t placeNewNote (event.latLng); \t setTimeout (function() # noteTitle " 500), }); – thomas

관련 문제