代码之家  ›  专栏  ›  技术社区  ›  sanoj lawrence

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

  •  1
  • sanoj lawrence  · 技术社区  · 6 年前

    我正在使用下列 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 或者没有 输入按钮

    如何在select上提交表单 (click ()function)

    2 回复  |  直到 6 年前
        1
  •  2
  •   c2huc2hu    6 年前

    我不认为当用户选择某个东西时自动提交表单是个好主意。他们没有时间确认发送了正确的结果或纠正了错误的单击。上面说,给你:

    从文档中:

    事件

    您可以使用默认的 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());
    
        2
  •  0
  •   Kavian Rabbani    6 年前

    我认为@user3080953的答案是正确的,你可以通过任何你想geocomplete的回调, 另一个例子:

    $("#geocomplete").geocomplete({
        details: "form",
        types: ['geocode', 'establishment'],
        country: 'in'
    })
    .bind('geocode:result', function(event, target){
        $("body").css("background-color", "red");
        $('#location').submit();
    });
    

    你可以在这里看到更多的钩子 geocomplete documentation (事件部分)。