0
하나의 HTML 페이지에 드롭 다운 목록 국가, 도시 및 지구가 있고 처음 비어있는 선택된 값과 Google지도가 있습니다. 사용자가 드롭 다운 목록에서 위치 값을 선택하면지도를 가운데로 확대/축소하려고합니다.Javascript/ASP.net 드롭 다운 목록 변경 후 이벤트 발생
- 사용자가 국가가 국가 드롭 다운리스트를 형성 선택
그래서 여기에 내가 문제를 직면 시나리오입니다.
- 드롭 다운 목록이 변경된 후 선택한 값을 검색해야합니다.
- 화재 구글지도를
를 업데이트 할 수있는 이벤트가 나는 onchange를 사용하고 자바 스크립트 이벤트를 변경 시도했지만 모두 드롭 다운리스트에서 검색 텍스트의 값이 이벤트 전에 텍스트의 값으로 인해 발생하는 빈 텍스트 (초기 빈 텍스트)를 Google지도에 보냅니다.
그럼 어떻게 드롭 다운 목록이 변경된 후에도 이벤트를 실행할 수 있습니까?
<asp:DropDownList ID="DropDownList_Country" runat="server" Height="29px" Width="209px"
Font-Size="18px" CausesValidation="false" onchange="MapLocationUpdater();">
function MapLocationUpdater() {
var address = getDropdownListAddress();
geocoder.geocode({ 'address': address },
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(11);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
}
);
}
function getDropdownListAddress() {
var ddlCountry = document.getElementById("<%=DropDownList_Country.ClientID%>");
var ddlCity = document.getElementById("<%=DropDownList_City.ClientID%>");
var ddlDistrict = document.getElementById("<%=DropDownList_District.ClientID%>");
var CountryTxt = ddlCountry.options[ddlCountry.selectedIndex].text;
var CityTxt = ddlCity.options[ddlCity.selectedIndex].text;
var DistrictTxt = ddlDistrict.options[ddlDistrict.selectedIndex].text;
return CountryTxt + " " + CityTxt + " " + DistrictTxt;
}
매우 흥미로운 해킹을
그리고 여기 내 코드입니다. 창피하다! – Eyad