如何关闭html输入表单字段建议? [英] How to turn off html input form field suggestions?

查看:137
本文介绍了如何关闭html输入表单字段建议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过建议,我的意思是下拉菜单在您开始输入时出现,它的建议是基于您之前输入的内容:

By suggestions I mean the drop down menu appear when you start typing, and it's suggestions are based on what you've typed before:

例如,当我在标题字段中输入'a'时,它会给我很多建议,这很烦人.有人知道如何关闭它吗? 提前致谢.

for example when I type 'a' in title field, it will give me a ton of suggestions which is pretty annoying.Does anyone know how to turn that off? Thanks in advance.

推荐答案

您要禁用HTML autocomplete属性.

What you want is to disable HTML autocomplete Attribute.

在此处设置autocomplete ="off"有两个效果:

Setting autocomplete="off" here has two effects:

它使浏览器停止保存字段数据以供以后自动完成 试探法因浏览器而异,但形式相似.它停止了 浏览器从会话历史记录中缓存表单数据.当表单数据是 缓存在会话历史记录中,用户填写的信息将 在用户提交表单并点击 返回"按钮返回到原始表单页面.

It stops the browser from saving field data for later autocompletion on similar forms though heuristics that vary by browser. It stops the browser from caching form data in session history. When form data is cached in session history, the information filled in by the user will be visible after the user has submitted the form and clicked on the Back button to go back to the original form page.

有关 MDN网络

这是一个示例.

<form action="#" autocomplete="on">
  First name:<input type="text" name="fname"><br> 
  Last name: <input type="text" name="lname"><br> 
  E-mail: <input type="email" name="email" autocomplete="off"><br>
  <input type="submit">
</form>

如果它在React框架上,则按如下方式使用:

If it's on React framework then use as follows:

<input
    id={field.name}
    className="form-control"
    type="text"
    placeholder={field.name}
    autoComplete="off"
    {...fields}/>

链接到反应文档

更新

这是一个修复程序,用于修复某些浏览器跳过"autocomplete = off"标志的更新.

Here's an update to fix some browsers skipping "autocomplete=off" flag.

<form action="#" autocomplete="off">
  First name: <input type="text" name="fname" autocomplete="off" readonly onfocus="this.removeAttribute('readonly');"><br> Last name: <input type="text" name="lname" autocomplete="off" readonly onfocus="this.removeAttribute('readonly');"><br> E-mail:
  <input type="email" name="email" autocomplete="off" readonly onfocus="this.removeAttribute('readonly');"><br>
  <input type="submit">
</form>

这篇关于如何关闭html输入表单字段建议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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