The 1th method is most people traditional approach, replace the HTML code, the upstairs has been used, I just use a regular optimization;
The 2nd method uses SendKeys to simulate keyboard operation, and needs to allow the browser to invoke ActiveX.
The 3rd method, a bit like martial arts in the "great diversion of the universe," like, oh, see To know!
<ptml> <pead> <title> to empty the value of input file type--test by programming prodigal </title> <script> function cle ArMethod1 () {var objfile=document.getelementsbytagname (' input ') [0]; Alert ("\" "+objfile.value+" \ "cleared"); Objfile.outerhtml=objfile.outerhtml.replace (/(value=\ "). +\"/I, "$1\"); function clearMethod2 () {var objfile=document.getelementsbytagname (' input ') [0]; Alert ("\" "+objfile.value+" \ "cleared"); var wshshell=new activexobject ("Wscript.Shell"); Objfile.focus (); Objfile.createtextrange (). Select (); Wshshell.sendkeys ("{del}"); function clearMethod3 () {var objfile=document.getelementsbytagname (' input ') [1]; Alert ("\" "+objfile.value+" \ "cleared"); Objfile.value= ""; } </script> <pead> <body> <input type= "file" value= "C:\abc.txt"/><br><br> <but Ton onclick= "clearMethod1 ();" > Clear Dafa 1: Lidaitaojiang </button><br> <button onclick= "clearMethod2 ();" > Clear Dafa 2: Sneak </button> <br><br><br><br><br><br><br> <input type= "text" value= ""/><input type= "file" value= "C:\abc.txt" onchange= "This.previoussibling.value=this.value;"/><br><br> <button onclick= "clearMethod3 ();" > Clearing Dafa 3: Diversion </button> </body> <ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
A method that opens the default value for the file field
<ptml> <pead> <title>input file Assign initial value--test by programming wave Sub </title> <script> function Getinitval () {var objfile=document.getelementsbytagname (' input ') [0]; var wshshell=new activexobject ("Wscript.Shell"); Objfile.focus (); Wshshell.sendkeys ("C:\\abc.txt"); } </script> <pead> <body onload= "Getinitval ()" > <input type= "File"/> (to ActiveX) <br>< ;br><br><br> <input type= "text" value= "C:\abc.txt"/><input "file" type= " This.previoussibling.value=this.value; " /> (direct simulation) </body> <ptml>
[ctrl+a All selected note: If you need to introduce external JS need to refresh to perform]