如何在文本框中删除自动完成功能

I need to remove autocomplete in all the textbox with in my page so I have given <input name="txt_username" id="txt_username" type="text" value="" autocomplete="off" /></dd></dl>

But it's not working does anyone know this?

Autocomplete, unless you're doing something crazy with AJAX, is a client-side thing and you can't always control it like that.

Since autocomplete works by caching your previous entries for a specific input text name, many banks randomly generate the input text name at each form page load but keep track of what is generated either somewhere else in a hidden input element or on the server side.

So instead of

<input name="txt_username" id="txt_username" type="text" value="" autocomplete="off" />

It might be something like

<input type="text" name="f6Lx571p" id="txt_username"/>
<input type="hidden" name="username_key" value="f6Lx571p" />

And the server-side code adjusted accordingly. For example, PHP code might have looked like:

<?php
$user = $_POST['txt_username'];
...

but it would have to be changed to something like:

<?php
$user = $_POST[$_POST['username_key']];
...

Its a bit annoying, but it works.

You can also try placing that autocomplete attribute on the form element.

<form id="myForm" autocomplete="off">
  ...
</form>

This will probably invalidate your HTML so you might want to consider adding this attribute dynamically with JavaScript.

Autocomplete cannot be turned off, it's something from the browser. What I do if I want to turn off autocomplete is the following:

Start a session with a field name and random number:

session_start();
$_SESSION['strUsername'] = "username_" . mt_rand(0, 1000000);

Now use this variable as the field's name:

name="' . $_SESSION['strUsername'] . '" id="txt_username" type="text" value="" autocomplete="off" /></dd></dl>

To check the value of the field simply use

$username = $_POST[$_SESSION['strUsername']];

Now, the name will be random everytime, so the browser will not recognize the field and will not give the autocompletion.

Autocomplete cannot be turned off, it's something from the browser, but I think this must help:<input type="password" name="password" readonly onfocus="this.removeAttribute('readonly')">