启用浏览器的表单自动填充 [英] Enabling browser's form auto-filling

查看:329
本文介绍了启用浏览器的表单自动填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的网站制作一份注册表格.它包含各种标准表单字段.例如:姓名,地址,电话号码,用户名,密码等.

I am making a signup form for my website. It contains various standard form fields. Such as: name, address, phone number, user name, password, etc.

当我双击一个字段(在Chrome 16中)以便自动填写地址时,会显示以下消息:

When I double-click on a field (in Chrome 16), so I can auto-fill my address, I get this message:

此网页已禁用此表格的自动填充功能.

This webpage has disabled automatic filling for this form.

我没有禁用它,那么如何启用它呢?我尝试在<form>标签和<input>标签中添加autocomplete="on",但这无济于事.

I didn't disable it, so how do I enable it? I tried adding autocomplete="on" to the <form> tag, and to (some of) the <input> tags, and that didn't help.

我需要在每个字段中添加autocomplete="on"吗?此外,浏览器如何知道什么字段是什么?我需要给字段命名一些特殊的内容吗?

Do I need to add autocomplete="on" to every field? Also, how does the browser know what field is what? Do I need to name the fields something special?

另一个问题:自动填写表单时是否触发某种onautocomplete事件?在我的表单上,当您输入邮政编码时,它将在我们的数据库中查找(通过AJAX),然后获取州和城市(城市和州属于下拉列表,因为邮政编码可以用于多个城市),并将其填入为你.我希望可以在自动填写表格后运行该程序.

Another question: Is there some kind of onautocomplete event that gets triggered when a form is auto-filled? On my form, when you enter a zip code, it looks in our database (via AJAX) and then gets the state and city (city and state are dropdowns, because zip codes can be for more than one city), and fills them in for you. I was hoping I could have that run after the form was auto-filled.

P.S.我正在使用jQuery的表单验证插件,

P.S. I'm using the jQuery form validation plugin, if that matters.

推荐答案

问题是表单标记上没有method="POST".

The problem was that the form tag didn't have method="POST" on it.

搜索该消息后,我发现了一个错误报告,并且其中评论之一提到.

After Googling the message, I found a bug report, and one of the comments mentioned method="POST".

我添加了method="POST",瞧!自动填充有效.

I added method="POST", and voila! Auto-fill works.

在某些情况下,如果表单不包含action,则可能还需要添加action. action="javascript:void(0)"有效.

In some cases you may also need to add an action if the form doesn't have one. action="javascript:void(0)" works.

注意:自动填充似乎触发了onchange事件.

Note: Auto-fill seems to trigger the onchange event.

注2:至于浏览器如何知道什么是字段,请参见以下问题:

Note 2: As for how the browser knows what field is what, see this question: How to trigger Autofill in Google Chrome?

这篇关于启用浏览器的表单自动填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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