基本上有三种方法可以实现
- 通过 opacity:0 和定位隐藏就可以在使用button的美化样式和input[file]的功能。
<div class="upload">
<button></button>
<input type="file" name="file" id="file">
</div>
<style>
#file{
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
opacity:0;
}
</style>
2.通过label的for属性 绑定input,使用label的样式和input[file]的功能
<label>uplaod<input type="file" style="display: none;"/></label>
3.通过onclick事件获取input操作
<button class="ui-upload" onclick="document.getElementById('upload').click()">upload</button>
<input type="file" id="upload" style="display:none;" />