我正在使用以下google geo autocomplete
代码
<form action="submit.php" method="POST" id="location">
<input id="geocomplete" type="text" placeholder="Type in an address" value="" />
<fieldset>
<h3>Address-Details</h3>
<label>Name</label>
<input name="name" type="text" value="">
<label>Latitude</label>
<input name="lat" type="text" value="">
<label>Longitude</label>
<input name="lng" type="text" value="">
<label>Formatted Address</label>
<input name="formatted_address" type="text" value="">
<input type="submit" name="submit">
</fieldset>
</form>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/geocomplete/1.7.0/jquery.geocomplete.min.js"></script>
<script>
$(function () {
$("#geocomplete").geocomplete({
details: "form",
types: ['geocode', 'establishment'],
country: 'in'
});
$("#find").click(function () {
$("#geocomplete").trigger("geocode");
$("#location").submit();
});
});
</script>
根据代码,一旦我从submit
中选择了位置,表格就应该autocomplete
,但不是
注意:有人可以帮我解决有input button
或没有input button
的问题
如何在选择(click ()function)
上提交表单
答案 0 :(得分:2)
我认为当用户选择某些内容时自动提交表单不是一个好主意。他们将没有时间确定是否发送了正确的结果或纠正了误点击。话虽这么说,这里您去了:
从文档中:
事件
您可以使用默认值订阅地理编码插件的事件 jQuery语法:
$("input") .geocomplete() .bind("geocode:result", function(event, result){ console.log(result); });
支持以下事件:
"geocode:result"
-地理编码成功。按照说明传递原始结果 here。
在您的示例中:
$("#geocomplete").geocomplete({
details: "form",
types: ['geocode', 'establishment'],
country: 'in'
})
.bind('geocode:result', $('#location').submit());
答案 1 :(得分:0)
我认为@ user3080953的答案是正确的,您可以传递要进行地理填充的任何回调, 另一个例子:
$("#geocomplete").geocomplete({
details: "form",
types: ['geocode', 'establishment'],
country: 'in'
})
.bind('geocode:result', function(event, target){
$("body").css("background-color", "red");
$('#location').submit();
});
您可以在geocomplete documentation(事件部分)中看到更多的钩子。