CSS 阻止浏览器文本输入建议

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/783573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:32:01  来源:igfitidea点击:

Preventing Browser Text Input Suggestions

cssbrowseruser-interface

提问by David Haddad

I am building my own local search UI element that gives local search suggestions as you type. The problem I am having is that when I focus on the html text input element my browser (Safari, but could happen in other browsers) displays its own text suggestions based on things that I've typed in the past.

我正在构建我自己的本地搜索 UI 元素,它会在您键入时提供本地搜索建议。我遇到的问题是,当我关注 html 文本输入元素时,我的浏览器(Safari,但可能发生在其他浏览器中)会根据我过去输入的内容显示自己的文本建议。

My guess is that this is dependent on the ID or Class of the < input > tag. So probably, if I change the input tag class to something obscure, the browser will not have any suggestions to offer. But I wonder if there isn't a more elegant way...

我的猜测是,这取决于 <input> 标签的 ID 或 Class。所以很可能,如果我将输入标签类更改为一些晦涩的东西,浏览器将不会提供任何建议。但我想知道是否有更优雅的方式......

A related issue is about text field highlighting that happens in Safari when you focus on the < input > element. When I am filling up a form on Facebook, I don't see this outline. It would be great to hear if someone knows how to handle those two issues.

一个相关的问题是当您将注意力集中在 < input > 元素上时,Safari 中出现的文本字段突出显示。当我在 Facebook 上填写表格时,我看不到这个大纲。很高兴听到有人知道如何处理这两个问题。

回答by zombat

Gecko-based browsers support a tag attribute called "autocomplete". So in your <form>tag you would put <form autocomplete="off">.

基于 Gecko 的浏览器支持称为“自动完成”的标签属性。所以在你的<form>标签中你会放<form autocomplete="off">.

More here: https://developer.mozilla.org/en/How_to_Turn_Off_form_Autocompletion

更多信息:https: //developer.mozilla.org/en/How_to_Turn_Off_form_Autocompletion

Some other browsers have support for this as well. I believe IE will honor this.

其他一些浏览器也支持这一点。我相信 IE 会尊重这一点。