【发布时间】:2014-02-07 06:34:20
【问题描述】:
我有一个文本字段,用户应该在其中输入地址。单击搜索按钮后,将执行一个函数,该函数使用该地址查找附近的 POI。这运作良好。但是,当用户点击返回键时,文本字段的值不会保存在变量中。这会导致使用地址变量的旧值执行搜索。
说实话,我什至不明白为什么它会有所不同。
HTML
<form action="" method="post">
<input type="text" class="innenfeld" id="addressInput" name="addressInput">
<input type="button" class="send" onclick="newsearch()"/>
</form>
JavaScript
function newsearch() {
var address = document.getElementById("addressInput").value;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
searchLocationsNear(results[0].geometry.location);
} else {
alert(address + ' not found');
}
});
}
【问题讨论】:
标签: javascript html textfield