給<input type="file">增加樣式
參考:
1. http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
2. http://pan.baidu.com/s/1F9Uqy
3. http://stackoverflow.com/questions/4909228/style-input-type-file
這篇文章用的是bootstrap。我用的是semantic-ui也差不多
1.搞個button出來
<span class="ui fluid button btn-file">
<span id="buttonLabel">選擇圖片</span> <input type="file" name="img">
</span>
2. 搞個CSS
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
3. 搞個JS
$(document).on('change', '.btn-file :file', function() {
var input = $(this),
numFiles = input.get(0).files ? input.get(0).files.length : 1,
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
input.trigger('fileselect', [numFiles, label]);
});
4. JS要這麼用
$(document).ready( function() {
$('.btn-file :file').on('fileselect', function(event, numFiles, label) {
console.log(numFiles);
console.log(label);
$("#buttonLabel").text(label);
});
});
相關文章
- input type="file"使用
- input[type="radio"]自定義樣式
- input[type=file]使用css美化效果CSS
- 如何清除<input type="file">的值
- type=“file”的input標籤美化
- <input type="file">實現各個瀏覽器樣式統一程式碼例項瀏覽器
- <input type="file"> 限制檔案型別型別
- <input type="file">美化例項程式碼
- 設定input type為text的文字框樣式
- <input type="file"> 選中多個檔案
- <input type="file">美化效果程式碼例項
- css設定type為text的input元素的樣式CSS
- 使用Input type=file 原生上傳使用總結
- js清空<input type="file">值程式碼例項JS
- jquery動態新增和刪除<input type="file" />jQuery
- input[type=file]不能選擇同一張圖片
- jQuery動態新增或刪除<input type="file">元素jQuery
- input框type=file設定cursor:pointer的問題
- input[type=file] 獲取上傳檔案的內容
- 修改input標籤type=file型別按鈕的值型別
- vue3中清空input type="file"上傳檔案Vue
- 如何獲取<input type="file">上傳的檔名稱
- css設定具有指定type屬性值的input文字框的樣式CSS
- JavaScript input type=file 獲取檔案大小及型別限制JavaScript型別
- HTML input type=file檔案選擇表單元素二三事HTML
- HTML中input type="text"和type="password" 顯示的長度不一樣HTML
- CSS input文字框樣式CSS
- CSS input 文字框樣式CSS
- react input[type='number']React
- utl_file.file_type使用
- JQuery獲取input type=jQuery
- 將input type="file" 型別的圖片檔案轉成base64型別
- No input file specified.
- 清空file input框
- File type 屬性
- CSS 設定input文字框樣式CSS
- css設定input文字框樣式CSS
- <input type="file">連續選中同一檔案無法觸發onchange事件事件