输入类型=“文件” javascript点击模拟
我想知道为什么这个示例在 Chrome 10 中有效,但在 Fx 3.6 中不起作用? IFAIK,确切的输入类型=“文件”点击在那里不起作用...
任何人都可以解释一下,为什么?
I'm wondering why this example works this in Chrome 10, but doesn't work in Fx 3.6?
IFAIK, exactly input type="file" click doesn't work there...
Could anyone explain, why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嘿 Alex Ivasyuv,
阅读您的问题并查看您所指向的页面。
您已将按钮的单击事件定向到右侧的单击事件吗?我认为这并不是在所有地方都是可能的。文件输入类型处理弹出窗口并自行上传。
并且似乎您无法仅通过调用 click() 事件来触发弹出文件上传窗口。至少在 Firefox、opera、chrome 等浏览器中是不可能的。但是在 IE 中是可能的,对吗? (无论如何,IE 总是表现得很奇怪......!)
我发现了一些文章可能有助于解决这个问题。检查它们。你会解决这个问题...!
问候,
ADynaMic
Hey Alex Ivasyuv,
Read your problem and took a look at the page you have pointed.
You have directed click event of the button to the click event of right? As I think that's not quite possible everywhere. The file input type handles the popups and uploads itself..
And seems you cannot trigger the popup file upload window of just by calling click() event. At least it's not possible in the browsers like Firefox, opera, chrome etc. But it's possible in IE right? (IE always behave strangely anyway..!)
I found some articles that may help to figure this out. check them. You'll solve the problem...!
Regards,
ADynaMic
我最近在谷歌上搜索这个并决定提出我自己的解决方案。
对于那些正在寻找解决方案的人,请参阅我的存储库 - Fancy Upload jQuery 插件
这是 jQuery 的一个小插件,但欢迎您将其剪下来或使用它作为您的代码库 - 无论如何!它只是设计了您的标准上传按钮,并为您提供了更多的自定义空间。
该插件的代码如下所示。可以使用 $('INPUT[type=file]').fancyUpload(); 在任何文件上传元素上调用它。
I was Googling this recently and decided to come up with my own solution.
For those of you looking for a solution please see my repo - Fancy Upload jQuery Plugin
This is a small plugin for jQuery but you are welcome to snip it up or use it as your code base - whatever! It just styles up your standard upload button and gives you a lot more room for customisation.
The code for this plugin can be seen below. It can be called on any file upload element using $('INPUT[type=file]').fancyUpload();
在 Android 上(出于安全原因),最初接收用户单击的单击处理程序必须与将单击发送到文件输入元素的逻辑相同。因此,可以隐藏文件输入元素(例如,如果您想从菜单选择触发上传)。
例如,以下代码(包含在 JsFiddle: 中):
On Android (for security reasons) the click handler that originally received the user's click must be the same logic that sends a click to a file input element. Thus the file input element can be hidden (for example, if you want to trigger an upload from a menu selection).
For example, following code (contained in JsFiddle:):