我需要一些关于此代码的帮助。我试图将id="address"
值放入名为localizacion
的输入中,我尝试了几件事但仍未找到正确答案,基本上我需要的是获取显示<div id="address">
的值并将其输入到输入字段中。
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
}
&#13;
<head>
<script>
var a = document.getElementById('address').value;
document.forms['formula'].elements['localizacion'].value = a;
</script>
</head>
<div>
<form>
<label for="localizacion"><b>Localización </b></label>
<input class="form-control" type="text" placeholder="" name="localizacion" style="height: 10px; width: 299px; margin-left: 6px;" disabled><br />
<label><b>Seleccione su localizacion: </b></label><br>
<div id="mapCanvas"></div>
<div id="infoPanel">
<b>Marker status:</b>
<div id="markerStatus"><i>Click and drag the marker.</i></div>
<b>Current position:</b>
<div id="info"></div>
<b>Closest matching address:</b>
<div id="address"></div>
</div>
<br>
</form>
</div>
&#13;
问题的屏幕截图:
答案 0 :(得分:0)
您可以定位form-control
类,并将其设置为address
的innerText的值。
setInterval(function(){
//Update the localizacion box every 0.5 seconds
var a = document.getElementById('address').value;
document.getElementsByClassName("form-control")[0].value = a;
}, 500);
我摆脱了<i>
标签。使用CSS代替斜体。同时删除了<b>
代码的<strong>
代码。希望这可以帮助。 Fiddle
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
}
var a = document.getElementById('address').innerText;
document.getElementsByClassName("form-control")[0].value = a;
//document.forms['formula'].elements['localizacion'].value = a;
&#13;
#markerStatus{
font-style: italic;
}
&#13;
<label for="localizacion"><b>Localización </b></label>
<input class="form-control" type="text" placeholder="" name="localizacion" style="height: 10px; width: 299px; margin-left: 6px;" disabled><br>
<label><strong>Seleccione su localizacion: </strong></label><br>
<div id="mapCanvas"></div>
<div id="infoPanel">
<strong>Marker status:</strong>
<div id="markerStatus">Click and drag the marker.</div>
<strong>Current position:</strong>
<div id="info"></div>
<strong>Closest matching address:</strong>
<div id="address">Some Address</div>
</div>
<br>
&#13;
答案 1 :(得分:0)
试试这个,使用
var a = document.getElementById('address').innerHTML;
获取地址值
document.getElementsByName("localizacion")[0].value = a;
设置本地化值
var a = document.getElementById('address').innerHTML;
document.getElementsByName("localizacion")[0].value = a;
<input class="form-control" type="text" placeholder="" name="localizacion" style="height: 10px; width: 299px; margin-left: 6px;" disabled>
<div id="address">Sample</div>