bootstrap改變上傳文件按鈕樣式,並顯示已上傳文件名

參考博文:
  html中,文件上傳時使用的<input type="file">的樣式自定義


html中<input type="file">默認樣式很醜,這裏用了Bootstrap按鈕的樣式,並獲取文件名顯示在其右側html

閒話少敘,直接上代碼:this

<label for="jobData" class="control-label" style="float:left;padding-left:15px;">任務數據</label>
<div class="col-xs-12 col-sm-4 col-md-4">
    <div class="file-container" style="display:inline-block;position:relative;overflow: hidden;vertical-align:middle">
        <button class="btn btn-success fileinput-button" type="button">上傳</button>
        <input type="file" id="jobData" onchange="loadFile(this.files[0])" style="position:absolute;top:0;left:0;font-size:34px; opacity:0">
    </div>
    <span id="filename" style="vertical-align: middle">未上傳文件</span>
</div>
<script>
function loadFile(file){
    $("#filename").html(file.name);
}
</script>



上傳文件前:
image.pngspa

上傳文件後:
[image.png](//upload-images.jianshu.io/upload_images/4334050-3fe5c6e61ac567fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240code

相關文章
相關標籤/搜索