怎么使用jquery实现不用点击file类型的input弹出文件选择对话框
可以使用trigger方式,javascript中没有原生的trigger函数,可以自己写一个,也可以直接使用jquery的实现:
代码如下:
var button1 = document.getElementById("button1");
var button2 = document.getElementById("button2");
button1.onclick = function(){alert("button1");trigger(button2,"onclick");}
button2.onclick = function(){alert("button2");}
function trigger(ele,event)
{ele[event]();}
也可以使用更加简单的方式,就是将input覆盖住要点击的图片或者超链或者其它div,然后将input设置成完全透明,这样点击图片时其实点击的是input,如下:
<div class="ps-image" style="width:300px;height:300px;border:0px sold red; background:url('/images/ps.png')">
<input type="file" id="file" style="filter:alpha(opacity=0);opacity:0;width:100%;height:100%;"/>
</div>
本文标题:怎么使用jquery实现不用点击file类型的input弹出文件选择对话框
本文链接:https://www.qqooo.cn/post/6674.html
版权说明:网站文章均来源于手工整理和网友投稿,若有不妥之处请来信 xsds@vip.qq.com 处理,谢谢!