I'm trying to style an input type="file" element by hiding it and creating a link to click the input element. My code works on an iPhone 5 but not on my Galaxy Nexus (Android).
My code:
<input id="files" type="file" accept="image/*;" class="hidden" />
<div id="button" onclick="files.click();">Take picture</div>
What do I have to do to make it work on Android?
I would comment on your question, but I do not have enough reputation. There you might find the answer to your question (or rather explanation, why it does not work – security reasons):
In JavaScript can I make a "click" event fire programmatically for a file input element?
onclick="files.click();"
Should be:
onclick="document.getElementById('files').click();"
But you better use unobtrusive javascript, avoid writing inline javascript code inside the html.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.