當用戶更改位置字段中的輸入時,我需要清除位置禁用的輸入。當輸入發生變化時從一組輸入中移除內容
這是我的代碼:http://jsfiddle.net/spadez/6v3kbLbk/7/
var placeSearch, autocomplete;
var componentForm = {
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'long_name',
country: 'long_name',
postal_code: 'short_name'
};
function initialize() {
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')), {
types: ['geocode']
});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
fillInAddress();
});
}
function fillInAddress() {
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
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;
}
}
}
使用谷歌自動提示我能夠與返回的信息來填充字段。不過,我碰到一個問題,當出現以下情況:
用戶鍵入一個地址 點擊自動完成(其中費爾場) 用戶刪除或新的輸入修改電流輸入 Uuser類型,但犯規點擊自動完成
的一部分這會在自動填充字段中留下舊值。我需要的是檢查字段中的內容是否已更改,如果有,請刪除帶紅色邊框的字段中的內容。
任何人都可以告訴我這可能是怎麼完成的?我的猜測是這樣的:
$('#autocomplete').keyup('input', function() {
$(".disabledclass").val('');