谷歌地图自动完成反弹已经清除文字... ....奇奇奇... [英] google maps autocomplete bounces back already cleared text ...odd....odd...odd

查看:398
本文介绍了谷歌地图自动完成反弹已经清除文字... ....奇奇奇...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从谷歌地图自动完成这一奇怪的行为(或者也许我错过某事)...想法?奇怪的:


  1. 您输入折腾到输入,例如伦敦

  2. 您$​​ P $ PSS [设置]

  3. 您$​​ P $ PSS [CLEAR]按钮

  4. 您点击进入输入

  5. 您点击输入之外

......瞧!步骤3文本(伦敦在我们的例子)已经被清除是右后卫到输入...为什么?

这里是code:

 <!DOCTYPE HTML>
< HTML和GT;
< HEAD>
     <脚本类型=文/ JavaScript的SRC =htt​​p://maps.google.com/maps/api/js?sensor=false&libraries=places>< / SCRIPT>
< /头>
<身体GT;    < H1>我FORM< / H1>
    <输入类型='文本'ID ='myInput'大小= '50'占位符='请输入文字'>
    <输入类型=按钮值=清除的onclick ='clearInput()'>    <脚本>
                变种myInput =的document.getElementById('myInput');
                无功自动完成=新google.maps.places.Autocomplete(myInput);
                功能clearInput(){
                    myInput.value ='';
                }                myInput.addEventListener('变',函数(){
                        的console.log(事件['目标'] ['值']);                },FALSE);    < / SCRIPT>
    < /身体GT;
< / HTML>


解决方案

在回答为什么的复杂,因为API源的来源是COM pressed,很难说什么是真正对那里发生的。

当然输入的值必须存储在某个地方,因为它必须在某些情况下,可以恢复(例如,当你的下拉的值之间进行切换)。

基本上是一个自动完成用于监听输入4事件:

 重点的keydown,KEYUP,模糊

这些事件都不会激发你的功能,所以自动完成可能无法识别新的价​​值。

可能的解决办法:触发你的函数这些事件:

 函数clearInput(){
  google.maps.event.trigger(myInput,'专注');
  myInput.value ='';
  google.maps.event.trigger(myInput的keydown',{键code:46});
  google.maps.event.trigger(myInput,'KEYUP',{键code:46});
  google.maps.event.trigger(myInput,'模糊');
}

您可以发送错误报告,这不是预期的行为,应该是固定的。

I have this odd behavior from Google MAPs autocomplete (or maybe I miss sth)... ideas? The odd:

  1. You enter sth into the input, e.g. 'London'
  2. You press [ENTER]
  3. You press [CLEAR] button
  4. You click into the 'input'
  5. You click outside the 'input'

....... and voila! The already cleared in step-3 text ('London' in our example) is right-back into the input...Why?

And here is the code:

<!DOCTYPE html>
<html>
<head>
     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script>
</head>
<body>

    <h1>MY FORM</h1>
    <input type='text' id='myInput' size='50' placeholder='Enter text'>
    <input type='button' value='clear' onclick='clearInput()'>

    <script>
                var myInput = document.getElementById('myInput');
                var autocomplete = new google.maps.places.Autocomplete(myInput);
                function clearInput(){
                    myInput.value = '';
                }

                myInput.addEventListener('change', function(){
                        console.log(event['target']['value']);

                }, false);

    </script>
    </body>
</html>

解决方案

Answering the "why" complicated, because the source of the API-source is compressed, hard to say what's really going on there.

Of course the value of the input must be stored somewhere, because it must be restored in some cases(e.g. when you switch between the values of the dropdown).

Basically an autocomplete is listening for 4 events in the input:

focus, keydown, keyup, blur

None of these events will fire in your function, so the autocomplete may not recognize the new value.

Possible solution:trigger these events in your function:

function clearInput(){
  google.maps.event.trigger(myInput,'focus');
  myInput.value = '';
  google.maps.event.trigger(myInput,'keydown',{keyCode:46});
  google.maps.event.trigger(myInput,'keyup',{keyCode:46});
  google.maps.event.trigger(myInput,'blur');
}

You may send a bug-report, this is not the expected behaviour and should be fixed.

这篇关于谷歌地图自动完成反弹已经清除文字... ....奇奇奇...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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