Home > Article > Web Front-end > Parse and use JS to clear the path value of the File control_javascript skills
1. Questions about how to modify the value of the fileupload control using scripts,
In the development environment vs2005, when uploading a file, a cancel button is needed to clear the value of type=file, and there are multiple file controls on this page
This is more troublesome because the value of file itself is not allowed to be modified by script (for security reasons)
Method 1). Use a script to move the input of this file into a form, and then call reset. If there are multiple such inputs, of course they have to be moved out again. I will not use this method because it will .net developer
For me, I am used to having one page and one form with all the controls in it.
Method 2). This method is a bit speculative, which is to call
var fileup = document.getElementById(fileid);
fileup.outerHTML = fileup.outerHTML; This ie is correct Related to script processing and display mechanism
Method 3). This is mainly considered when solving the problem on ff. In fact, it regenerates a file with the same ID. It should be noted here that the name must also be assigned a value, otherwise it will be difficult to submit to
accepted by the serverIn normal project development, there is a function to upload files. Generally, the front end will use JS to determine whether the uploaded file belongs to the specified file type. If it does not belong, the control value will be cleared! (Of course, you can also not clear it)
There is a very simple way to clear the value of the file upload component. The code is as follows:
var file=document.getElementById("form1:fileupload");
file.outerHTML =file.outerHTML
The above method can be used in IE
In order to be compatible with FireFox, we use the following method to clear the value of the fileupload control:
That’s it, all browsers support it