简体   繁体   English

HTML 5链接/屏蔽 <input type='file'> 到了

[英]HTML 5 Linking/Masking <input type='file'> to an <a>

If the title confuses you; 如果标题混淆了你; what's the most elegant way to mask the difficult <input type='file'/> to a friendly <a/> so when the <a> is selected, the file explorer is prompted? 什么是将困难的<input type='file'/>掩盖到友好的<a/>的最优雅的方式,所以当选择<a>时,会提示文件浏览器?

You can simulate a click with jQuery like this. 您可以像这样使用jQuery模拟点击。

<input type='file' id="myInput"/>
    <a href="#" id="myAnchor">Launch File Upload</a>

​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

$("#myAnchor").click(function () {

    $("#myInput").trigger('click');

});

Working Fiddle 工作小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM