Method for customizing the input box style of the file type

Source: Internet
Author: User
When uploading files on the WEB, the upload box is used:

<Input type = "file" id = "f" name = "f">

This is a very special object in IE (others are not tested.

If it is a value that you manually write or other objects are triggered by certain events

Due to security issues, the submitted form is often cleared, so the upload fails.

To put it simply, IE will upload the file to you unless you have clicked f on the upload box!

Even if you assign the onclick handle of f to an object, for example:
<Input type = "file" id = "f" name = "f">
<Input onclick = "f. click ()" value = "click">

After you click, the file selection dialog box will also pop up. Unfortunately, you are disappointed that you still cannot upload files!

What should we do?

Take a look at this section:

<BODY onmousemove = "f. style. pixelLeft = event. x-200; f. style. pixelTop = events. y-10;">
<Input type = "text"> <input type = "button" onmousemove = "">
<Input type = "file" id = "f" name = "f" style = "position: absolute;">
</BODY>

 

Click the mouse to see the effect?

Based on the above idea, we can get it under a button and it will be OK !!

 

<Style>
Input {}{ border: 1px solid green ;}
</Style>
<BODY>
<BR>
<Form method = "post" action = "" enctype = "multipart/form-data">
<Input type = "text" id = "txt" name = "txt">
& Nbsp; <input type = "button" onmousemove = "f. style. pixelLeft = event. x-60; f. style. pixelTop = this. offsetTop; "value =" select a file "size =" 30 ">
<Input type = "file" id = "f" name = "f" style = "position: absolute;" size = "1" onChange = "txt. value = this. value "> <BR>
<Input type = "submit">
</Form>
</BODY>

 

To achieve the Simulated effect, you must hide f, add an opaque alpha filter, and add the hidefocus attribute to hide the dotted line of f:

 

<Style>
Input {}{ border: 1px solid green ;}
</Style>
<BODY>
<BR>
<Form method = "post" action = "" enctype = "multipart/form-data">
<Input type = "text" id = "txt" name = "txt">
& Nbsp; <input type = "button" onmousemove = "f. style. pixelLeft = event. x-60; f. style. pixelTop = this. offsetTop; "value =" select file "size =" 30 "onclick =" f. click () ">
<Input type = "file" id = "f" onchange = "txt. value = this. value "name =" f "style =" position: absolute; filter: alpha (opacity = 0); "size =" 1 "hidefocus> <BR>
<Input type = "submit">
</Form>
</BODY>

 

You can see that the opacity = 0 is slightly larger.

OK. Now you can control their style and position...

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.