1

ここに私のコードの一部があります:

<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() の値を問題なく取得できます (アラートで表示しようとすると、正しい値が返されます)。

4

1 に答える 1

3
document.getElementById("#<%= hdnLocationLatLng.ClientID %>")

# 文字を削除

于 2015-01-19T08:28:29.627 に答える