点击打开文件上传对话框 [英] open file upload dialog on click
问题描述
下面是我有的代码:
< input type =filestyle =visibility:隐; />
以下是javascript:
<$ p $ ();
$('input [type = file]')。click();
});
在Firefox 4和IE8中工作正常,但是在chrome12中它不工作,即对话框不是被打开。任何想法为什么?
现在测试问题和情况中给出的简单代码已经改变:
- IE9:作品
- Chrome23:作品
- Firefox15:作品 >
只有一个catch-on IE,.click()是一个阻塞操作,而在其他浏览器上则不是。 b $ b
I have to open file upload dialog by clicking some other button i.e i am hiding file upload control(visibility:hidden) and on clicking of some other button i want to open that dialog. Below is the code which i am having:
<input type="file" style="visibility: hidden;" />
Below is the javascript:
$('#button').click(function() {
$('input[type=file]').click();
});
It is working fine in Firefox 4 and IE8 but in chrome12 it is not working i.e the dialog is not being opened. Any idea why?
Tested today the simple code given in the question and the situation has changed:
- IE9: works
- Chrome23: works
- Firefox15: works
There is just one catch - on IE the .click() is a blocking operation while on other browsers it is not.
这篇关于点击打开文件上传对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!