JS gets and empties the value of the input type= "file"

Source: Internet
Author: User

  This article mainly introduces the JS access, empty input type= "file" value (sample code) needs of friends can come to the reference, I hope to help you.

The Upload control (<input type= "file"/>) is used to browse and upload files on the client, and the path that the user chooses can be obtained by the Value property, but the Value property is read-only and cannot be assigned through JavaScript, which makes it impossible to pass through the value= "" Statement to empty it. It is easy to understand why only read, if you can assign values, then the user just open your Web page, you can upload the files on his computer.   JS get <intput type=file/> Value   code as follows: <html> <script language= ' javascript ' >   function &n Bsp 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>   & lt;body> <input type= "file" Name= "File1" id= "File1" "Onpropertychange=" Show (); "/> <span the id=" s "></ span>   </body> </html>     Two ways to empty the value of the upload control (<input type= "file"/>)   Method 1:   Code As follows: <span   id=span1>   <input   name=ab   type=file>   </span>   <iNput   name=button1   Type=button   value= "by"   Onclick=show () >     <script   LAN guage=javascript>   function   Show ()   {  document.getElementById ("Span1"). Innerhtml= "< Input   name=ab   type=file> ";     </script>       Method 2: The code is as follows: function clearfileinput (file) {var form=document.createele ment (' form '); Document.body.appendChild (form);  //Remember the location 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); }  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.