Html 如何隐藏文本输入的浏览器生成的先前项目下拉列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1477520/
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
How to hide a text input's browser-generated dropdown list of previous items
提问by johannes
When I generate a text input like this:
当我生成这样的文本输入时:
<input type="text" name="name" />
When I start to type, the browser will display a dropdown list below the text input. This list contains the values I previously used for this text input in this browser. I want to generate my own autocompletion via ajax.
当我开始输入时,浏览器将在文本输入下方显示一个下拉列表。此列表包含我之前在此浏览器中用于此文本输入的值。我想通过 ajax 生成我自己的自动完成。
How do I tell the browser with either css or javascript to not generate this dropdown list.
如何使用 css 或 javascript 告诉浏览器不生成此下拉列表。
If this task is easier by using jquery, I would prefer such a solution.
如果使用 jquery 更容易完成这项任务,我更喜欢这样的解决方案。
回答by Peter Bailey
Both IE and Firefox (maybe others, I didn't research it much) support the autocomplete attribute. If you set it to "off" these browsers will no longer display the autocompletion.
IE 和 Firefox(也许其他的,我没有研究太多)都支持autocomplete 属性。如果您将其设置为“关闭”,这些浏览器将不再显示自动完成功能。
<input type="text" autocomplete="off" />