2017-04-16 30 views
1
function wnw_set_google_autocomplete_my(){ 
    jQuery(gaaf_fields_my).each(function(){ 

     var autocomplete_my= new google.maps.places.Autocomplete(
     /** @type {HTMLInputElement} */(this), 
     { types: ['geocode'] }); 
     // When the user selects an address from the dropdown, 
     // populate the address fields in the form. 

    }); 
} 
jQuery(window).load(function(){ 
    wnw_set_google_autocomplete_my(); 
}); 

链接:http://35.154.204.251/contact/谷歌自动完成Places API的错误InvalidValueError

我已经在WordPress安装了谷歌的自动完成地方API和我在控制台越来越InvalidValueError,我无法找出问题,因为每一件事情是对我看来很好。

回答

2

查看变量gaaf_fields_my的值。当我把一个破发点,我可以看到这个变量具有以下值

" [name="input_2"], [name="demo"], #input_2_2, #demo, .address, .demo"

的问题是,jQuery(gaaf_fields_my)回报作为第一元素具有类“地址”,是不是<input>一个<li>元素。这会导致自动完成构造函数中的一个异常,该构造函数需要输入元素作为参数,但您尝试在<li>上初始化它。

enter image description here

你应该申请一个更好的选择或调用自动完成构造函数之前检查jQuery的循环内的元素的标签名称:

function wnw_set_google_autocomplete_my(){ 
    jQuery(gaaf_fields_my).each(function(){ 

     if (this.tagName.toLowerCase() === 'input') { 

      var autocomplete_my= new google.maps.places.Autocomplete(
       /** @type {HTMLInputElement} */(this), 
       { types: ['geocode'] }); 

     } 
    }); 
} 
+0

由于做工精细:) – himanshuahuja

+0

顺便说一句什么突破型点你用过的 – himanshuahuja

相关问题