【发布时间】:2016-02-14 09:25:14
【问题描述】:
我有一个表单字段,用户可以在其中输入他们的地址。为了让用户的生活更轻松,我在此字段中添加了 google Places API 地址自动完成功能。在您开始使用本机浏览器自动完成之前,一切都适用于这种方法。如果用户在他们的网络浏览器上设置了自动完成功能,我显然希望他们能够使用它......表单越快越好。但是,当用户在我的地址字段上时,本机自动完成和谷歌位置自动完成最终会相互竞争(本机在谷歌位置之上)。它看起来很糟糕,对于任何想要使用 GP 自动完成功能的人来说,这也是一种糟糕的用户体验。
我的自然倾向是在地址字段上简单地切换autocomplete="off"(使用focus 和blur):
$search_address
//don't allow autocomplete when users are in this field as it messes with GP input
.on('focus', function(e){
$(this).attr('autocomplete', 'off'); console.log('autocomplete off');
})
//if the user is not in the field, allow autocomplete, or it messes with native AutoFill
.on('blur', function(e){
$(this).removeAttr('autocomplete'); console.log('autocomplete on');
});
我可以从我的控制台日志中得知这些正在触发,但是本机浏览器自动完成功能并未被删除。我不确定如何处理这种情况。任何人都想到了一种方法来做到这一点,或者可能知道为什么这不起作用?
【问题讨论】:
-
你不能简单地在
-
事实上,现在我已经再次阅读了这个问题,并且您希望其他表单字段的本地自动完成功能,使用
<input type="text" autocomplete="off">为这个表单字段设置自动完成功能
标签: javascript jquery html autocomplete google-places-api