2017-11-18 110 views
1

我一直在试图将Algolia Places应用到我的注册页面,并努力让它适用于城市输入。Algolia Places错误“container”必须指向<input>元素

控制台错误: 未捕获错误:Algolia Places:'container'必须指向一个元素。

我已经试过各种选择都没有成功:

  • 容器: “#ID城”
  • 容器:document.querySelector( '#id_city')
  • 容器:document.querySelector( '输入#id_city')
  • 容器:document.querySelector( “输入[ID = 'id_city']”)
  • 容器:document.querySelector( “输入[名称= '城市']”)

我敢肯定,这是愚蠢的东西,但不知道我做错了什么......

感谢您的帮助!

<input type="text" class="form-control " name="city" id="id_city" value="" size="20" maxlength="120"> 


<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> 
<script> 

var options = { 
    container: "#id-city", 
    type: "city", 
}; 
places(options); 
</script> 
+0

奥利弗结帐的答案,如果是足够您的需要 –

回答

1

只是以下是好的。运行该片段。

<script type="text/javascript"> 
     var placesAutocomplete = places({ 
     container: document.getElementById('id_city') 
     }); 
    </script> 

<!DOCTYPE html> 
 
<html> 
 

 
    <head> 
 
    <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> 
 
    </head> 
 

 
    <body> 
 
    <input type="text" class="form-control " name="city" id="id_city" value="" size="20" maxlength="120" /> 
 
<script type="text/javascript"> 
 
    var placesAutocomplete = places({ 
 
    container: document.getElementById('id_city') 
 
    }); 
 
</script> 
 

 
    </body> 
 

 
</html>

+0

啊谢谢,我已经试过了剧本,但我的错误是把所有的代码在标题中,而之前不是身体正在关闭。 –

相关问题