0

我正在使用 geocomplete.js API 以及 google maps api。

搜索自动完成地址、郊区或任何工作,当我按下回车键时,这些字段会自动填充。

我的问题是当我尝试以编程方式触发回车键时,它没有注册为用户按下回车键。因此,如果我按 Enter 键,文本框不会像通常那样填写地理位置详细信息。

如何自动输入文本字段并自动从下拉列表中收集结果?

这是代码

<input type="text" id="inputmap" />
    <div id="map"></div>
    <form action="" id="mapform">
        latitude: <input type="text" data-geo="lat" /> <br>
        longitude: <input type="text" data-geo="lng" /> <br>
        Address: <input type="text" data-geo="formatted_address" /> <br>
        Country: <input type="text" data-geo="country" /> <br>
        Country Code: <input type="text" data-geo="country_short" /> <br>
        PCode: <input type="text" data-geo="postal_code" /> <br>
        Locality: <input type="text" data-geo="locality" /> <br>
        Sub-Locality: <input type="text" data-geo="sublocality" /> <br>

    </form> 
    <script>
        $('#inputmap').geocomplete({
            map: '#map',
            details: '#mapform',
            detailsAttribute: "data-geo"
        });


        $(document).ready(function() 
        {
            var e = jQuery.Event("keydown");
            e.keyCode = 50;   

            setTimeout(function()
            {
                $('#inputmap').val("sydney").focus();
            }, 1000);
            setTimeout(function()
            {

                $('#inputmap').trigger(e);  
                alert("pressed");

            }, 3000);


        });




    </script>
4

0 回答 0