Autocomplete is not working in html with chrome

2019-09-01 08:36发布

问题:

Sometimes in my web application even I declare form autocomplete is off sometimes its not working and it autocomplete I typed in my inputs.

Can anyone know how to solved this kind of problem.I use chrome by the way.

sample of my code: sometimes its autocompleting my inputs even I declare turn off already..

<form autocomplete="off" method="post">
    <input autocomplete="off" type="text" name="name">
    <input autocomplete="off" type="text" name="age">
    <input type="submit" >
</form>

回答1:

<form autocomplete="off" method="post">
<input autocomplete="off" type="text" name="name"  value="">
<input autocomplete="off" type="text" name="age"  value="">
<input type="submit" >
</form>


回答2:

The solution is simple and working perfectly in all browsers.

  1. Add disabled and autocomplete="off" attribute to the form fields( name, age, etc.)

    <form method="post">
      <input disabled="disabled" autocomplete="off" type="text" class="name" name="name">
      <input disabled="disabled" autocomplete="off" type="text" class="age" name="age">
      <input type="submit" >
    </form>
    
  2. On Page Load enable the fields after few miliseconds.

use the below JS CODE

function getRidOffAutocomplete(){               
    var timer = window.setTimeout( function(){
        $('.name, .age').prop('disabled',false);
            clearTimeout(timer);
        }, 800);
    }

// Invoke the function
getRidOffAutocomplete();


回答3:

This isn't a bug - autocomplete isn't supported by Chrome any more. It's a design decision by their developers and you should design for it rather than attempting to work around it. See my answer to this very similar question.