小编Joh*_*son的帖子

如何触发Google的place_changed事件在Enter键上自动完成

点击似乎触发事件并设置cookie但按Enter键提交不会设置cookie,而是页面重定向而没有cookie.

function locationAuto() {
        $('.search-location').focus(function () {
        autocomplete = new google.maps.places.Autocomplete(this);
        searchbox = this;

        google.maps.event.addListener(autocomplete, 'place_changed', function () {
            var thisplace = autocomplete.getPlace();
            if (thisplace.geometry.location != null) {
                $.cookie.raw = true;
                $.cookie('location', searchbox.value, { expires: 1 });
                $.cookie('geo', thisplace.geometry.location, { expires: 1 });
            }
        });
});
Run Code Online (Sandbox Code Playgroud)

.search-location是多个文本框上的一个类.有一个提交按钮,可以从cookie和重定向中获取值(服务器端)

autocomplete google-places

34
推荐指数
3
解决办法
5万
查看次数

标签 统计

autocomplete ×1

google-places ×1