Home > Web Front-end > JS Tutorial > body text

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

一个新手
Release: 2017-09-08 13:08:18
Original
4326 people have browsed it


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);  
        }  
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template