var city = $('#city')[0].value; AMap.plugin(['AMap.Autocomplete'],function(){ var autoOptions = { city: city, input: community, }; autocomplete= new AMap.Autocomplete(autoOptions); AMap.event.addListener(autocomplete, "select", function(e){ $('#community')[0].value = e.poi.name }); });
记得加上
<link rel="stylesheet" href="https://cache.amap.com/lbs/static/main.css"/>
<script type="text/javascript"
src="https://webapi.amap.com/maps?v=1.4.2&key=您申请的key值"></script>
<script type="text/javascript" src="https://webapi.amap.com/demos/js/liteToolbar.js"></script>