地理自动完成中的点击功能错误提交表单

submit form on click function error in geo autocomplete

正在使用以下 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 一旦我 select 位置来自 autocomplete 但它不会

注意:谁能帮我解决 input buttoninput button

的问题

如何在 select(click ()function)

上提交表格

我不认为当用户选择某些内容时自动提交表单是个好主意。他们将没有时间确保发送了正确的结果或更正误点击。话虽这么说,给你:

来自文档:

Events

You can subscribe to events of the geocode plugin by using the default jQuery syntax:

$("input")
  .geocomplete()
  .bind("geocode:result", function(event, result){
    console.log(result);
  });

The following events are supported:

  • "geocode:result" - Geocode was successful. Passes the original result as described here.

在你的例子中:

$("#geocomplete").geocomplete({
    details: "form",
    types: ['geocode', 'establishment'],
    country: 'in'
})
.bind('geocode:result', $('#location').submit());

我认为@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(事件部分)中看到更多挂钩。