Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Google place按类名自动完成不起作用_Jquery_Google Maps_Google Maps Api 3_Autocomplete - Fatal编程技术网

Jquery Google place按类名自动完成不起作用

Jquery Google place按类名自动完成不起作用,jquery,google-maps,google-maps-api-3,autocomplete,Jquery,Google Maps,Google Maps Api 3,Autocomplete,您好,我有一个文本框,它会自动完成place,street,name,如果我按id选择,它会为我工作,但后来我有许多动态文本框控件,因此我有固定的类名,如果我按classname 代码: getPlace(); getPlace_dynamic(); function getPlace() { var defaultBounds = new google.maps.LatLngBounds( new google.maps.LatLng(-3

您好,我有一个文本框,它会自动完成place,street,name,如果我按
id
选择,它会为我工作,但后来我有许多动态文本框控件,因此我有固定的类名,如果我按
classname

代码:

 getPlace();
 getPlace_dynamic();

     function getPlace() {
         var defaultBounds = new google.maps.LatLngBounds(
         new google.maps.LatLng(-33.8902, 151.1759),
         new google.maps.LatLng(-33.8474, 151.2631));
         var input = document.getElementById('Destination');
         // var input = document.getElementsByClassName('destination');
         var options = {
             bounds: defaultBounds,
             types: ['establishment']
         };
         autocomplete = new google.maps.places.Autocomplete(input, options);
     }

     function getPlace_dynamic() {
         var defaultBounds = new google.maps.LatLngBounds(
         new google.maps.LatLng(-33.8902, 151.1759),
         new google.maps.LatLng(-33.8474, 151.2631));

         var input = document.getElementsByClassName('myClass');
         var options = {
             bounds: defaultBounds,
             types: ['establishment']
         };
         autocomplete = new google.maps.places.Autocomplete(input, options);
     }




以后动态生成
返回具有该类名的元素数组(
myClass

所以您需要做的是迭代每个元素并将其分配给GoogleAutoCompleteAPI,如下所示

for (i = 0; i < input.length; i++) {
        autocomplete = new google.maps.places.Autocomplete(input[i], options);
}
for(i=0;i

尝试更改此行
var input=document.getElementsByClassName('myClass')
getElementById
并为第二个和第三个ID提供一些特定的
ID
sinputs@Pavlo:by id正在工作,我需要选择by classname,因为它从第三方生成了Dynamicly。Praveen的答案应该可以解决您的问题issue@Praveen好的。非常有用。感谢您的解决方案在JSFIDLE上不起作用,请更新。
document.getElementsByClassName('myClass')
for (i = 0; i < input.length; i++) {
        autocomplete = new google.maps.places.Autocomplete(input[i], options);
}