先上圖吧~css
樣式OK,測試功能正常。html
思路:測試
技巧:this
css以下:spa
/*自定義input-file上傳樣式*/ .otoc-uploadfile-box{ position: relative; width: 100%; height: 36px; box-sizing: content-box; } .otoc-uploadfile-box > input[type=file]{ position: absolute; top: 0; left: 0; filter: alpha(opacity:0); opacity: 0; width: 100%; height: 36px; cursor: pointer; z-index: 2; } .otoc-uploadfile-box > input[type=text]{ position: absolute; top: 0; left: 0; padding-left: 3px; width: 75%; height: 36px; border: 1px solid #ccc; z-index: 0; } .otoc-uploadfile-box > button[type=button]{ position: absolute !important; top: 0; right: 0; width: 25%; height: 36px; z-index: 0; color: #fff; background-color: #36c6d3; border:1px solid #2bb8c4; user-select:none; }
css以下: code
<div class="otoc-uploadfile-box"> <input type="file" id="stockUpload" onchange="document.getElementById('textfield').value=this.value"> <input type="text" id="textfield"> <button type="button">瀏覽文件</button> </div>