Basic knowledge about upload controls:
The upload control (<input type = "file"/>) is used to browse and upload files on the client. The path selected by the user can be obtained by the value attribute, but the value attribute is read-only, the value cannot be assigned through javascript, so that it cannot be cleared through the value = "" statement. It is easy to understand why it is read-only. If you can assign a value at will, you can upload files on your computer as you like by simply opening your webpage.
Js gets the value of <intput type = file/>
Copy codeThe Code is as follows:
<Html>
<Script language = 'javascript '>
Function show (){
Var p = document. getElementById ("file1"). value;
Document. getElementById ("s"). innerHTML = "<input id = pic type = image height = 96 width = 128/> ";
Document. getElementById ("pic"). src = p;
Alert (p );
}
</Script>
<Head>
<Title> MyHtml.html </title>
</Head>
<Body>
<Input type = "file" name = "file1" id = "file1" onpropertychange = "show ();"/>
<Span id = "s"> </span>
</Body>
</Html>
Two Methods for clearing the value of the upload control (<input type = "file"/>)
Method 1:
Copy codeThe Code is as follows:
<Span id = span1>
<Input name = AB type = file>
</Span>
<Input name = button1 type = button value = "Press" onclick = show ()>
<Script language = javascript>
Function show ()
{
Document. getElementById ("span1"). innerHTML = "<input name = AB type = file> ";
}
</Script>
Method 2:
Copy codeThe Code is as follows:
Function clearFileInput (file ){
Var form = document. createElement ('form ');
Document. body. appendChild (form );
// Remember the position of the file in the old form
Var pos = file. nextSibling;
Form. appendChild (file );
Form. reset ();
Pos. parentNode. insertBefore (file, pos );
Document. body. removeChild (form );
}