How to trigger a <input type="file"> element using jquery
Is ther开发者_运维知识库e a way to trigger the click even of :
<input id="test" type="file">
?
I was looking for the same thing and found an answer at trigger file upload dialog using javascript/jquery and a running example is at http://jsfiddle.net/CSvjw/
it simply does
$('#test').trigger('click');
Dont use display:none or visibility:hidden initially in the css
In Jquery:
$(document).ready(function() {
$('#test').hide();
});
There is no way to trigger the upload window programmatically, however if you just want to hide the ugly "choose a file"-button and inputfield, there is a simple solution.
Just hide the input using any old technique and add a label refering to it. You can then style the label any way you want. Clicking the label will trigger the upload window.
For example:
<input id="test" type="file" style="display: none" />
<label for="test" class="make-it-look-like-a-button">Upload</label>
As far as I know, there is no way to trigger it programmatically for security reasons. You got to click it explicitly.
Not possible (security reasons).
No, there isn't, and this is a good thing as it would be extremely annoying for the user. Whether a user wants to upload some file is in is control only, personally I would hate a site automatically sticking an Open Dialog into my nose when I visit it.
精彩评论