如何防止在Chrome中预填表单元素 [英] How to prevent form elements from pre-populating in Chrome

查看:168
本文介绍了如何防止在Chrome中预填表单元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Bootstrap表单,并且电子邮件和密码表单元素会使用来自某个其他网站或某个其他网站上早期表单登录的预填充数据显示。 Chrome浏览器会自动填充表单元素。



Bootstrap中是否有方法的HTML属性强制这些表单元素在页面加载时为null或为空? p>

2015-10-29 - 这是标记:

 < form autocomplete =offmethod =postrole =form> 
< div class =form-group>
< input name =formSubmittedtype =hiddenvalue =1>
< / div>
< div class =form-group>
< label for =用户名>用户名< / label>
< input autocomplete =offautofocus =autofocusclass =form-controlid =usernamename =usernamerequired type =text>
< / div>
< div class =form-group>
< label for =password>密码< / label>
< input autocomplete =offclass =form-controlid =passwordname =passwordrequired type =password>
< / div>
< button class =btn btn-defaulttype =submit>登入< / button>
< / form>


解决方案

使用 autocomplete =off < form> 或<输入>

中的 属性。来自 MDN 的b
$ b

a>:


自动填充
$ b 此属性表示该控件的值是否可以是由浏览器自动完成的



off
用户必须明确地输入为每个用途赋予此字段的值,或者文档提供自己的自动完成方法;
浏览器不会自动完成该条目。



on
允许浏览器根据用户在以前使用过程中输入的值...


另外从MDN中,请参阅: 如何关闭表单自动完成功能

另见:


I am building a Bootstrap form and the email and password form elements show with pre-populated data from some other or some earlier form login on a different site. The Chrome browser is auto-populating the form elements.

Is there an HTML attribute of method in Bootstrap to force these form elements to null or empty on page load?

2015-10-29 -- here's the markup:

      <form autocomplete="off" method="post" role="form">
        <div class="form-group">
          <input name="formSubmitted" type="hidden" value="1">
        </div>
        <div class="form-group">
          <label for="username">Username</label>
          <input autocomplete="off" autofocus="autofocus" class="form-control" id="username" name="username" required type="text">
        </div>
        <div class="form-group">
          <label for="password">Password</label>
          <input autocomplete="off" class="form-control" id="password" name="password" required type="password">
        </div>
        <button class="btn btn-default" type="submit">Login</button>
      </form>

解决方案

Use the autocomplete="off" attribute on the <form> or <input>.

from MDN:

autocomplete

This attribute indicates whether the value of the control can be automatically completed by the browser.

off
The user must explicitly enter a value into this field for every use, or the document provides its own auto-completion method; the browser does not automatically complete the entry.

on
The browser is allowed to automatically complete the value based on values that the user has entered during previous uses...

Also from MDN, see: How to Turn Off Form Autocompletion

Also see:

这篇关于如何防止在Chrome中预填表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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