Javascript 输入字段无法识别动态数据

Javascript 输入字段无法识别动态数据,javascript,jquery,html,Javascript,Jquery,Html,我有一个反向地理位置代码,它返回一个格式化的地址,然后动态添加到一个谷歌地图地址字段,该字段将自动更新地图。问题是,google地图更新的唯一方式是在输入字段中添加空格键或任何类型的输入,就像它无法识别我通过document.getElementById('address').value动态添加的数据一样= 我尝试模拟输入字段的关键事件,使其相信添加了数据,我尝试使用google api手动刷新地图,但没有效果,我尝试拆分添加后添加的字符串,以查看它是否识别更改,我还尝试将输入字段的长度设置为+

我有一个反向地理位置代码,它返回一个格式化的地址,然后动态添加到一个谷歌地图地址字段,该字段将自动更新地图。问题是,google地图更新的唯一方式是在输入字段中添加空格键或任何类型的输入,就像它无法识别我通过document.getElementById('address').value动态添加的数据一样=

我尝试模拟输入字段的关键事件,使其相信添加了数据,我尝试使用google api手动刷新地图,但没有效果,我尝试拆分添加后添加的字符串,以查看它是否识别更改,我还尝试将输入字段的长度设置为+1,看看是否有效。我现在真的不知道该怎么办。下面是我当前试图使输入字段识别存在值的尝试

<span class="findme" id="find1"><i class="fa fa-compass" style="font-size:33px;color:green;"></i></span>      
<script>
var find1 = document.getElementById("find1");        
var info = document.getElementById("info");    
var selector = [];    
find1.addEventListener("click", function() {            
selector.push("jform_fulladdress");    
    getLocation();
}, false);            
function putInDom(address){    
  if(selector.length == 1){
    //one field for address
    var field = document.getElementById(selector[0]);
    field.value = address;
  }     
}

function getLocation(){
  if (navigator.geolocation){
    navigator.geolocation.getCurrentPosition(getAddress);
  } else{
    info.innerHTML="Geolocation is not supported by this browser.";
  }
}

function getAddress(position){    
  var lat = position.coords.latitude;
  var lon = position.coords.longitude;    
  var apiurl = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='+lat+','+lon+'&sensor=true';    
  var url = 'ba-simple-proxy.php?url='+encodeURIComponent(apiurl);    
  var xhr = new XMLHttpRequest();    
  xhr.open("GET", url);
  xhr.onload = function() {             
      if(this.status==200 && JSON.parse(xhr.responseText).contents.results.length > 0){
        var result = JSON.parse(xhr.responseText).contents.results[0].formatted_address;
        putInDom(result);
      } else {
        info.innerHTML = "Could not find your location.";
      }    
  }    
  xhr.send();
}        
jQuery('form').change(function() {
var splAd = document.getElementById('jform_fulladdress').value;
splAd = splAd.split(',').slice(0, 2).join(',');
document.getElementById('jform_maps_search').value= splAd;
document.getElementById('jform_fulladdress').value= splAd;

jQuery('jform_fulladdress')
  .trigger({
    type: 'keypress',
    which: character.charCodeAt(49)      
   });    
}).click(function() {
var splAd = document.getElementById('jform_fulladdress').value;
splAd = splAd.split(',').slice(0, 2).join(',');
 document.getElementById('jform_maps_search').value= splAd;
document.getElementById('jform_fulladdress').value= splAd;    
jQuery('jform_fulladdress')
  .trigger({
    type: 'keypress',
    which: character.charCodeAt(49)      
   });    
});    
</script>

var find1=document.getElementById(“find1”);
var info=document.getElementById(“info”);
var选择器=[];
find1.addEventListener(“单击”,函数(){
选择器.push(“jform_fulladdress”);
getLocation();
},假);
函数putinom(地址){
if(selector.length==1){
//一个地址字段
var字段=document.getElementById(选择器[0]);
field.value=地址;
}     
}
函数getLocation(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(getAddress);
}否则{
info.innerHTML=“此浏览器不支持地理位置。”;
}
}
函数getAddress(位置){
var lat=位置坐标纬度;
var lon=位置坐标经度;
var apiurl=https://maps.googleapis.com/maps/api/geocode/json?latlng=“+lat+”、“+lon+”&传感器=真”;
var url='ba simple proxy.php?url='+encodeURIComponent(apirl);
var xhr=new XMLHttpRequest();
xhr.open(“GET”,url);
xhr.onload=函数(){
if(this.status==200&&JSON.parse(xhr.responseText.contents.results.length>0){
var result=JSON.parse(xhr.responseText).contents.results[0]。格式化的\u地址;
putInDom(结果);
}否则{
info.innerHTML=“找不到您的位置。”;
}    
}    
xhr.send();
}        
jQuery('form').change(function(){
var splAd=document.getElementById('jform\u fulladdress')。值;
splAd=splAd.split(',').slice(0,2).join(',');
document.getElementById('jform\u maps\u search')。value=splAd;
document.getElementById('jform\u fulladdress')。value=splAd;
jQuery('jform\u fulladdress')
.扳机({
键入:“按键”,
其中:character.charCodeAt(49)
});    
})。单击(函数(){
var splAd=document.getElementById('jform\u fulladdress')。值;
splAd=splAd.split(',').slice(0,2).join(',');
document.getElementById('jform\u maps\u search')。value=splAd;
document.getElementById('jform\u fulladdress')。value=splAd;
jQuery('jform\u fulladdress')
.扳机({
键入:“按键”,
其中:character.charCodeAt(49)
});    
});