Home > Article > Web Front-end > How to clear the value of [type="file"] in input
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!