【问题标题】:How to disable browser autocomplete on Input element in React.js如何在 React.js 中的 Input 元素上禁用浏览器自动完成功能
【发布时间】:2020-04-20 22:24:03
【问题描述】:

几天前我遇到了这个问题。你有谁知道如何在 React.js 的 Input 元素上禁用浏览器自动完成功能? 我已经试过了:

  • autoComplete="关闭"
  • autocomplete="new-password"

两者都不工作。

感谢您的回答。

【问题讨论】:

  • 阅读更多关于这个大线程here。如果有,请在表单级别禁用自动完成功能。并确保使用autoComplete,加上大写的 C。但即便如此,你也可能会有惊喜。
  • @NicolaeOlariu 我在表单中没有输入,因为我是通过另一个组件提交的。所以我需要在输入级别禁用自动完成。

标签: html reactjs google-chrome autofill


【解决方案1】:

来自https://www.codementor.io/@leonardofaria/disabling-autofill-in-chrome-zec47xcui的解决方案

对我来说解决问题的方法是将表单字段设置为只读,然后在用户关注它们后删除该属性。

<input readonly="readonly" onfocus="this.removeAttribute('readonly');" type="text" value="test">

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-05-05
  • 2011-02-17
  • 2015-03-02
  • 1970-01-01
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 2019-03-31
相关资源
最近更新 更多