如何激发place_changed事件谷歌放在回车键自动完成 [英] How to fire place_changed event for Google places auto-complete on Enter key

查看:542
本文介绍了如何激发place_changed事件谷歌放在回车键自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的点击,似乎触发事件,并设置Cookie,但pressing进入提交不设置cookies和替代页面重定向没有饼干。

The click seems to fire the event and set the cookies but pressing enter to submit doesn't set the cookies and instead the page redirects without the cookies.

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 });
            }
        });
});

该.search-位置是在多个文本框的类。
有一个提交按钮,从饼干和重定向所采用的值(服务器端)

The .search-location is a class on multiple textboxes. There is a submit button that takes the values from the cookies and redirects (server side)

推荐答案

从乔纳森·考尔菲尔德的回答改编:

Adapted from Jonathan Caulfield's answer:

$('.search-location').keypress(function(e) {
  if (e.which == 13) {
    google.maps.event.trigger(autocomplete, 'place_changed');
    return false;
  }
});

这篇关于如何激发place_changed事件谷歌放在回车键自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆