html - Firefox 自动填充/自动完成不断填写新的用户名/密码表单
问题描述
我正在尝试创建一个表单,管理员用户可以在其中创建一个新用户并为其设置密码,但 Firefox 会继续使用最初登录的用户凭据填写这些表单元素。
这就是我的 html 的样子:
<input id="account-un" class="new-user-name" type="text" placeholder="Please set a password for this account" value="" autocomplete="off">
<input id="account-psw" class="new-user-password" type="password" placeholder="Please set a password for this account" value="" autocomplete="new-password">
我autocomplete="off"
在这两个领域都尝试过,但似乎没有任何效果。有什么方法可以防止 Firefox 或/和任何其他浏览器自动填充这些表格?
我正在使用 Firefox 63.0.3
解决方案
我没有检查过,但你可以试试这个旧的解决方案:
if (document.getElementsByTagName) {
var inputElements = document.getElementsByTagName(“input”);
for (i=0; inputElements[i]; i++) {
if (inputElements[i].className && (inputElements[i].className.indexOf(“disableAutoComplete”) != -1)) {
inputElements[i].setAttribute(“autocomplete”,”off”);
}
}
}
来源:https ://css-tricks.com/snippets/html/autocomplete-off/#comment-88998
推荐阅读
- vue.js - 在 VueJS 中渲染持久化的动态模板
- javascript - 你如何在 Python 中执行一个 for 循环,循环遍历 html 中的输入字段并检查它们的值
- rust - 将关联的非可变常量数据分配给枚举变量
- node.js - Node.js:使用 .p12 证书和公司代理生成令牌时出错
- c# - 如何获取同域远程机器的登录用户名
- javascript - 下拉菜单不变
- embedded-linux - ubifs eroor ubi0 警告:ubi_io_read:imx28 上的错误 -74(ECC 错误)
- reactjs - 如何将“提醒”通知设置到特定时间-ReactJS
- python - 几次迭代后 HTTPX 套接字连接断开
- angular - 为什么我在使用 Angular 发布 url 时出现错误