如何防止浏览器记住文本字段内容? [英] How to prevent browser from remembering text field content?

查看:96
本文介绍了如何防止浏览器记住文本字段内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

是否有一种W3C有效的方式来禁用HTML表单中的自动填充?

有没有办法阻止浏览器不记住文本字段的内容?问题是该字段包含一个值,例如100,然后附加一个货币符号,如€使得 100€。如果我点击该字段,我的小部件将删除货币,我可以编辑裸号,当我模糊它时,会再次显示货币。一切正常,直到你点击F5,然后你最终有 100€€,因为浏览器恢复了原来的值 100€它有重新加载时发生,并重新添加小部件。

Is there a way I can prevent a browser from not remembering the content of a text field? The problem is that the field contains a value such as 100, and then gets appended a currency symbol such as € making it 100 €. If I click on the field, my widget removes the currency and I can edit the bare number, and when I blur it displays the currency again. Everything works fine until you hit F5 and then you end up having 100 € € because the browser restored the original value 100 € it had when the reload happened, and the widget re-added it.

推荐答案

对于支持它的浏览器, autocomplete 属性。从链接:

For browsers that support it, there's the new autocomplete attribute. From the link:


autocomplete 属性是一个枚举属性。该属性有三个状态。 关键字上的映射到 on 状态,而 off 关键字映射到<强>关状态。该属性也可以省略。 缺失值默认默认状态。

The autocomplete attribute is an enumerated attribute. The attribute has three states. The on keyword maps to the on state, and the off keyword maps to the off state. The attribute may also be omitted. The missing value default is the default state.

关闭状态表示控件的输入数据是特别的敏感的(例如核武器的激活码);或者它是一个永远不会被重用的值(例如用于银行登录的一次性密钥),因此用户每次都必须明确地输入数据,而不是依赖于UA来预先填充他的价值;或者文档提供了自己的自动完成机制,并且不希望用户代理提供自动完成值。

The off state indicates either that the control's input data is particularly sensitive (for example the activation code for a nuclear weapon); or that it is a value that will never be reused (for example a one-time-key for a bank login) and the user will therefore have to explicitly enter the data each time, instead of being able to rely on the UA to prefill the value for him; or that the document provides its own autocomplete mechanism and does not want the user agent to provide autocompletion values.

...虽然在在你描述的具体案例中,我想我可能只是将欧元符号保留在场外价值之外。您可以将它放在字段旁边,或者使用CSS将其叠加到字段上(例如,将它放在标记中的字段后面,然后使用 position:relative; left:-3em ,类似的东西)。但是如果你真的想阻止浏览器的自动填充, autocomplete 是工具箱的一个工具。

...although in the specific case you describe, I think I'd probably just keep the € symbol outside the field's value in the first place. You can put it next to the field, or superimpose it on the field using CSS (for instance, put it after the field in the markup and then use position: relative; left: -3em, that sort of thing). But if you really want to prevent the browser's auto-filling, autocomplete is one tool for the toolchest.

这篇关于如何防止浏览器记住文本字段内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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