【问题标题】:Google Places API: How can I select pac-container class using jQuery?Google Places API:如何使用 jQuery 选择 pac-container 类?
【发布时间】:2018-07-23 08:27:56
【问题描述】:

为什么我无法选择pac-container 类。

我正在使用 Google Places API

见下面pac-container类的截图:-

尝试了什么:-

$(document).on('click', '.pac-container', function() {
    alert('pac container class selected');
})

【问题讨论】:

    标签: javascript jquery google-maps


    【解决方案1】:

    我得到了这个问题的答案,实际上我在 document.ready 中调用了我的 Jquery 代码,但我需要在 Place Autocomplete 代码中使用它。

    Place Autocomplete 是在加载我的自定义 jquery 之前加载的,但自定义 jquery 应该使用 Place Autocomplete 加载。

    现在将我的代码放入函数中:-

    function ZipOrCityOnMobile() {
        if ($(window).width() < 768) {
            $('.m-search-close').hide();
            $('[name="ZipOrCity"]').parents('li').removeClass('search-control-mobile');
            $('.home-text').css('z-index', '9');
        }
    }
    

    然后在Place Autocomplete内部调用

    function initOfficeLocationAddLocationPicker() {
            var input = document.getElementById('ZipOrCity');
            var places = new google.maps.places.Autocomplete(input);
             // Set country for us.
            places.setComponentRestrictions({ 'country': ['us'] });
            google.maps.event.addListener(places, 'place_changed', function () {
                var address = AddressHepler(places.getPlace());
                if (address.postal_code != null && address.postal_code != '' && address.postal_code != undefined) {
                    var CityStateandZipcode = address.locality.concat(', ', address.state, ', ', address.postal_code);
                    $("#ZipOrCity").val(CityStateandZipcode);
                }
                else if (address.locality != null && address.locality != '' && address.locality != undefined) {
                    var CityandState = address.locality.concat(', ', address.state);
                    $("#ZipOrCity").val(CityandState);
                }
                else {
                    $("#ZipOrCity").val(address.state);
                }
                ZipOrCityOnMobile();
            });
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 2011-08-31
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 2017-01-09
      • 1970-01-01
      相关资源
      最近更新 更多