Default value emptying and assignment method for input file _javascript tips

Source: Internet
Author: User
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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.