Home > Article > Web Front-end > How to Hide the Text Field in an Input Type=File Element?
Hiding the Text Field in Input Type=File Element
Question:
How can I style or script an input type=file element to display only a "Browse" button without a text field?
Answer:
To achieve the desired effect, you can utilize the following HTML and JavaScript code:
With this code, the input type=file element with the id selectedFile will be hidden from view using the>
When the "Browse..." button is clicked, it triggers the click() event on the hidden input type=file element, allowing users to select files as usual. This approach allows you to hide the text field while maintaining the functionality of the input type=file element.
It's noteworthy that this solution is widely used and has proven successful in various projects.
The above is the detailed content of How to Hide the Text Field in an Input Type=File Element?. For more information, please follow other related articles on the PHP Chinese website!