本文介绍了Google地图自动填充表单自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为结帐页面实施了Google自动填充表单。能够将值填充到相应的输入字段。一旦用户从建议列表中选择建议的地址,我就将值填充到输入字段。在这里,我想要自动填充字段(用户首先键入的地方)#address.line1 值要更改。所以我实现了以下内容:

I have implemented google autocomplete form for checkout page. Am able to populate the values to respective input fields.Once the user selects an suggested address from suggestion list am populating the value to input fields. Here I want autocomplete field (where the user types first) #address.line1 value to be changed. So I have implemented the following:

 var street = document.getElementById("address.line1").value;
 var streetaddress= street.substr(0, street.indexOf(','));
 document.getElementById("address.line1").value = streetaddress;

上面的代码将获得#address.line1中的值并将值切成第一个逗号并放回#address.line1。

above code will gets value in #address.line1 and slice the value till first comma and puts back to #address.line1.

当我使用鼠标光标选择建议的地址时,所有工作正常但如果我使用键盘(箭头)选择建议,那么它不会切片地址。 #address.line1 正在填满整个 formated_adddress 数组。

All are working fine when I select suggested address using mouse cursor but if I use keyboard (arrows) to select suggestion then it wont slice the address. #address.line1 is getting filled with entire formated_adddress array.

演示:

截屏视频:

请建议我可能出现的问题和解决方案......

Please suggest me what might be the problem and solution...

推荐答案

必须发生这种情况,因为一次点击已经绑定在address.line1上。

This must be happening because one click is already binded on address.line1.

您可以做的是:


  1. 从此输入字段中删除焦点

document.getElementById(addressline1)。blur();
var streetaddress = street.substr(0,street.indexOf(','));
document.getElementById(addressline1)。value = streetaddress;


  1. 将焦点放在下一个输入字段(实际上在良好的用户体验方面是必需的)

  1. Give focus to next input field (which is actually required when it comes to good user experience)

$("#route").focus();

var streetaddress = street.substr(0,street.indexOf(','));
document.getElementById(addressline1)。value = streetaddress;

var streetaddress= street.substr(0, street.indexOf(','));document.getElementById("addressline1").value = streetaddress;

如果您还有其他疑问请给出意见。

If you have any more query please comment.

问候,

Suyash

这篇关于Google地图自动填充表单自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 13:14