jQuery触发文件输入 [英] jQuery trigger file input

查看:27
本文介绍了jQuery触发文件输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 jQuery 触发上传框(浏览按钮).
我现在试过的方法是:

Am trying to trigger an upload box (browse button) using jQuery.
The method I have tried now is:

$('#fileinput').trigger('click');   

但它似乎不起作用.请帮忙.谢谢.

But it doesn't seem to work. Please help. Thank you.

推荐答案

这是由于安全限制.

我发现只有当 <input type="file"/> 设置为 display:none; 或者是 可见性:隐藏.

I found out that the security restriction is only when the <input type="file"/> is set to display:none; or is visbilty:hidden.

所以我尝试通过设置 position:absolutetop:-100px; 将它定位在视口外,然后就可以了.

So i tried positioning it outside the viewport by setting position:absolute and top:-100px; and voilà it works.

http://jsfiddle.net/DSARd/1/

称之为黑客.

希望对你有用.

这篇关于jQuery触发文件输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆