页面代码:
- <span class="btn btn-success fileinput-button">
- <form enctype="multipart/form-data" id="uploadform">
- <input type="file" value="" name="file" onchange="imgupload()" >
- <span style="color: #921aff">上传照片</span>
- </form>
- </span>
样式:
样式改变后不能再用onclick事件,需要用在input file框上运用onchange事件。
- <style>
- .fileinput-button {
- position: relative;
- display: inline-block;
- }
- .fileinput-button input{
- position:absolute;
- right: 0px;
- top: 0px;
- opacity: 0;
- -ms-filter: 'alpha(opacity=0)';
- font-size: 20px;
- width:100px;
- }
- </style>