谷歌自动完成 - 输入选择 [英] Google Autocomplete - enter to select

查看:120
本文介绍了谷歌自动完成 - 输入选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的谷歌自动完成设置为HTML格式的文本字段,它的工作完美。

I have Google Autocomplete set up for a text field of an HTML form, and it's working perfectly.

然而,当建议列表中出现,并使用箭头滚动并选择使用输入,它提交表单,虽然仍有框填写。如果您单击以选中它工作得很好的建议,但pressing 输入提交。

However, when the list of suggestions appear, and you use the arrows to scroll and select using enter, it submits the form, though there are still boxes to fill in. If you click to select a suggestion it works fine, but pressing enter submits.

我如何控制呢?我怎样才能阻止提交表单输入,而是从自动完成建议的选择?

How can I control this? How can I stop enter from submitting the form, and instead be the selection of a suggestion from autocomplete?

谢谢!
{S}

Thanks! {S}

推荐答案

您可以使用时输入被击中提交 preventDefault 停止形式,我用是这样的:

You can use preventDefault to stop the form being submitted when enter is hit, I used something like this:

  var input = document.getElementById('inputId');
  google.maps.event.addDomListener(input, 'keydown', function(e) { 
    if (e.keyCode == 13) { 
        e.preventDefault(); 
    }
  }); 

这篇关于谷歌自动完成 - 输入选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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