Triggering File Input Using jQuery
When attempting to trigger an upload box using jQuery using the trigger('click'); method, users may encounter difficulties. However, this issue often arises from a security restriction.
The browser prevents clicking on hidden file input elements. If an element has its display set to none or visibility hidden, it cannot be clicked or triggered.
To circumvent this restriction, one approach is to position the file input element outside the viewport. By setting the position to absolute and the top margin to a negative value (e.g., top:-100px;), the element becomes inaccessible to users while remaining reachable through triggers. This method is available in a demonstration on jsfiddle: http://jsfiddle.net/DSARd/1/.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3