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/
我已经在 wordpress 中安装了 Google 自动完成 Place api 并且我在控制台中收到 InvalidValueError 并且我无法找出问题,因为对我来说一切都很好。
看看变量的值gaaf_fields_my
。当我放置一个断点时,我可以看到这个变量具有以下值
" [name="input_2"], [name="demo"], #input_2_2, #demo, .address, .demo"
问题是jQuery(gaaf_fields_my)
作为第一个<li>
元素返回一个具有类“地址”而不是<input>
. 这会导致自动完成构造函数中出现异常,该构造函数期望输入元素作为参数,但您尝试在 上对其进行初始化<li>
。
在调用自动完成构造函数之前,您应该应用更好的选择器或在 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'] });
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句