When obtaining a file in input = file mode, you cannot trigger the change event of input = file indirectly through a button click event in IE 8.

Source: Internet
Author: User

Recently, many upload problems have been encountered in the project. For internal components of the company to upload via form, you need to use input = file to trigger file selection,

Because input = file displays different styles in different browsers, Google, Firefox, and IE are different and not very beautiful

This problem occurs when the hidden input = file is used at the beginning, and then a display button is used to indirectly trigger the click event of input = file as follows:

<Input type = "file" id = "Upload" style = "display: none">

<Input type = "button" value = "Upload" onlick = "document. getelementbyid ('upload'). Click ()"/>

It has been tested that ie9 +, Google, and Firefox can be used normally and uploaded normally, but there is a problem in IE8, no matter how you choose

Cannot trigger the change event. After query, the original security restriction is based on, IE8 will indirectly trigger the input = file value, which leads

The change event cannot be triggered at all times. Then, after some time, Baidu finally developed a compatible thing:

<Div> <input type = 'file'> <A> upload </a> </div>

First, put the input = file side in a DIV, div sets position, and overflow = hidden, and make the input = File Size and Width sufficient to overwrite

The entire Div, at the same time make its transparency opacity 0, so that it can display the overwritten a mark upload, but the actual click is to overwrite the top input = file tag

This solves the compatibility issue.

There is also a small compatibility issue during the upload. It seems that in IE, for example, IE8, input = file is read-only. To clear input = file, after each upload is complete

You must manually clear the node, that is, clone the node first, and then replace the original node ..

Insufficient: However, there is still a problem in doing so. When the Google mouse moves the input = file tag, the mouse and hand type does not work, which leads to poor user experience, there is no solution yet.

The component is based on form upload, And the progress bar is not implemented. To ensure compatibility, HTML5 cannot be used. Therefore, I tried to upload the component in flash, and the result was a fiasco... Poor strength. Learn more.

 

When obtaining a file in input = file mode, you cannot trigger the change event of input = file indirectly through a button click event in IE 8.

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.