Home  >  Article  >  Web Front-end  >  How to clear the value of [type="file"] in input

How to clear the value of [type="file"] in input

一个新手
一个新手Original
2017-09-08 13:08:184310browse


Due to security mechanism issues, the value of input[type="file"] cannot be modified using js, so it cannot be reset like other form elements. After consulting the information, use the following method to reset:

function resetInputFile(inputfile){
    if(inputfile[0].value){        
    try{
            inputfile[0].value="";
        }catch(error){
        }        
        if(inputfile[0].value){            
        var form = document.createElement('form');            
        var existingItem= inputfile.nextSibling;            
        var parent = inputfile.parentNode;  
            form.appendChild(inputfile);  
            form.reset();  
            parent.insertBefore(inputfile,existingItem);  
        }  
    }
}

It has been verified that it cannot be used under IE. The reason is: IE does not allow moving elements in different documents, so form.appendChild(inputfile ); An error will be reported here that the program cannot be executed

The above is the detailed content of How to clear the value of [type="file"] in input. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn