我有一个Web应用程序,例如在示例页面中的输入字段中使用Google Maps自动完成功能:
但是,他们使用自动完成功能来划分信息并填写表格:
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
// Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
这不是我想要的。我需要的是带有该输入字段内容的简单javascript变量。像这样的东西var completeAddress = autocomplete.getFullAddress()
,但是这并不存在,而且如果没有复杂的循环和数组,我看不到有这样做的方法。
如何获得用户选择的文本?
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
document.getElementById('fulladdress').value = place.formatted_address;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句