Disable Firefox's Auto-fill

前端 未结 11 1347
天涯浪人
天涯浪人 2020-12-03 13:54

Is it possible to disable Firefox\'s auto-fill feature without disabling auto-complete?

I know I can do this:

autocomplete=\"off\"
<         


        
11条回答
  •  青春惊慌失措
    2020-12-03 14:10

    I had this problem myself. Mike's answer is close, but not perfect in my opinion: it empties elements, even if a value attribute may want to set it.

    On pageload, I do the following. It uses only a little jQuery.

    // Reset input elements to their HTML attributes (value, checked)
    $("input").each(function(){
        // match checkbox and radiobox checked state with the attribute
        if((this.getAttribute('checked')==null) == this.checked)
            this.checked = !this.checked;
        // reset value for anything else
        else this.value = this.getAttribute('value')||'';
    });
    
    // Select the option that is set by the HTML attribute (selected)
    $("select").each(function(){
        var opts = $("option",this), selected = 0;
        for(var i=0; i


    No jQuery?

    Use document.getElementsByTagName to select the inputs and selects, then iterate over them and replace this by the iterated element.
    Select the options with .getElementsByTagName('option').

提交回复
热议问题