当前位置: 动力学知识库 > 问答 > 编程问答 >

html - How to prevent browser from remembering text field content?

问题描述:

Possible Duplicate:

Is there a W3C valid way to disable autocomplete in a HTML form?

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.

网友答案:

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

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.

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.

...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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: