这是我的代码的一部分:
<asp:HiddenField id="hdnLocationLatLng" runat="server" Value="0" />
并且我正在尝试使用以下方法将hdnLocationLatLng的值设置为标记当前位置的latlng的值:
google.maps.event.addListener(map, 'click', function (event) {
if (marker) {
marker.setMap(null);
}
marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true,
title: "My Event's Location",
});
document.getElementById("#<%= hdnLocationLatLng.ClientID %>").value = marker.getPosition();
});
但是每次我点击地图时,都会收到错误消息:
Uncaught Type Error: Cannot set property 'value' of null.
仅供参考,我可以毫无问题地获得marker.getPosition()的值(试图在警报中显示它,并返回正确的值)。
document.getElementById("#<%= hdnLocationLatLng.ClientID %>")
删除#个字符
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句