Google found this solution:
When a value is inserted in the upload control, it can only be cleared through the form reset function, but other values in the form are also reset.
Now that you can use the form reset to clear, there is a way: create a temporary form, and then move the upload control to be cleared into it. After the reset, move back to the original location, finally, delete the created temporary form. Js Code:
Copy codeThe Code is as follows:
Var Upload = {
Clear: function (id ){
Var up = (typeof id = "string ")? Document. getElementById (id): id;
If (typeof up! = "Object") return null;
Var tt = document. createElement ("span ");
Tt. id = "_ tt __";
Up. parentNode. insertBefore (tt, up );
Var tf = document. createElement ("form ");
Tf. appendChild (up );
Document. getElementsByTagName ("body") [0]. appendChild (tf );
Tf. reset ();
Tt. parentNode. insertBefore (up, tt );
Tt. parentNode. removeChild (tt );
Tt = null;
Tf. parentNode. removeChild (tf );
},
ClearForm: function (){
Var inputs, frm;
If (arguments. length = 0)
{
Inputs = document. getElementsByTagName ("input ");
} Else {
Frm = (typeof arguments [0] = "string ")? Document. getElementById (arguments [0]): arguments [0];
If (typeof frm! = "Object") return null;
Inputs = frm. getElementsByTagName ("input ");
}
Var fs = [];
For (var I = 0; I <inputs. length; I ++)
{
If (inputs [I]. type = "file") fs [fs. length] = inputs [I];
}
Var tf = document. createElement ("form ");
For (var I = 0; I <fs. length; I ++)
{
Var tt = document. createElement ("span ");
Tt. id = "_ tt _" + I;
Fs [I]. parentNode. insertBefore (tt, fs [I]);
Tf. appendChild (fs [I]);
}
Document. getElementsByTagName ("body") [0]. appendChild (tf );
Tf. reset ();
For (var I = 0; I <fs. length; I ++)
{
Var tt = document. getElementById ("_ tt _" + I );
Tt. parentNode. insertBefore (fs [I], tt );
Tt. parentNode. removeChild (tt );
}
Tf. parentNode. removeChild (tf );
}
}
View plaincopy to clipboardprint?
Var Upload = {
Clear: function (id ){
Var up = (typeof id = "string ")? Document. getElementById (id): id;
If (typeof up! = "Object") return null;
Var tt = document. createElement ("span ");
Tt. id = "_ tt __";
Up. parentNode. insertBefore (tt, up );
Var tf = document. createElement ("form ");
Tf. appendChild (up );
Document. getElementsByTagName ("body") [0]. appendChild (tf );
Tf. reset ();
Tt. parentNode. insertBefore (up, tt );
Tt. parentNode. removeChild (tt );
Tt = null;
Tf. parentNode. removeChild (tf );
},
ClearForm: function (){
Var inputs, frm;
If (arguments. length = 0)
{
Inputs = document. getElementsByTagName ("input ");
} Else {
Frm = (typeof arguments [0] = "string ")? Document. getElementById (arguments [0]): arguments [0];
If (typeof frm! = "Object") return null;
Inputs = frm. getElementsByTagName ("input ");
}
Var fs = [];
For (var I = 0; I <inputs. length; I ++)
{
If (inputs [I]. type = "file") fs [fs. length] = inputs [I];
}
Var tf = document. createElement ("form ");
For (var I = 0; I <fs. length; I ++)
{
Var tt = document. createElement ("span ");
Tt. id = "_ tt _" + I;
Fs [I]. parentNode. insertBefore (tt, fs [I]);
Tf. appendChild (fs [I]);
}
Document. getElementsByTagName ("body") [0]. appendChild (tf );
Tf. reset ();
For (var I = 0; I <fs. length; I ++)
{
Var tt = document. getElementById ("_ tt _" + I );
Tt. parentNode. insertBefore (fs [I], tt );
Tt. parentNode. removeChild (tt );
}
Tf. parentNode. removeChild (tf );
}
}