1

我有两个文本框,我需要使用谷歌地方自动完成功能。这些文本框包含在页面加载时隐藏的面板中。有一个可供选择的选项列表,一旦获得用户输入,隐藏面板就会显示出来。我都试过了

    Panel.visible = false; 

    Panel.Style["display"] = "none";
    Panel.Style["visibility"] = "hidden";

但两者都不起作用。隐藏面板后,文本框的自动完成功能将停止工作。我最初无法显示面板。有解决办法吗?我可以在特定回发后触发自动完成吗?还是有什么其他方式?这是我用于自动完成的 javascript

    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
<script type="text/javascript">
    var defaultBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(7.623887, 68.994141),
    new google.maps.LatLng(37.020098, 97.470703));
    var input1 = document.getElementById('ctl00_ReportContentPlaceHolder_txtLocality1');
    var input2 = document.getElementById('ctl00_ReportContentPlaceHolder_txtLocality2');
    var options = {
        bounds: defaultBounds,
        types: ['geocode'],
        componentRestrictions: { country: "IN" }
    };
    autocomplete1 = new google.maps.places.Autocomplete(input1, options);
    autocomplete2 = new google.maps.places.Autocomplete(input2, options);

</script>
4

1 回答 1

0

我终于解决了我的问题......在这里找到了答案:https ://stackoverflow.com/a/8851767/972821

我有点意识到我必须在回发后重新初始化 javascript……但不确定它是如何完成的……谢谢 Aristos。这是我修改后的代码:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);

    function InitializeRequest(sender, args) {
    }

    // fires after the partial update of UpdatePanel
    function EndRequest(sender, args) {
        initialize();
    }
    function initialize() {
        var defaultBounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(7.623887, 68.994141),
        new google.maps.LatLng(37.020098, 97.470703));

        var input1 = document.getElementById('ctl00_ReportContentPlaceHolder_txtLocality');
        var input2 = document.getElementById('ctl00_ReportContentPlaceHolder_txtDropLocality');
        var options = {
            bounds: defaultBounds,
            types: ['geocode'],
            componentRestrictions: { country: "IN" }
        };
        autocomplete1 = new google.maps.places.Autocomplete(input1, options);
        autocomplete2 = new google.maps.places.Autocomplete(input2, options);
    }
</script>
于 2013-05-21T10:38:18.047 回答