回答編集履歴
1
調整
test
CHANGED
@@ -63,3 +63,75 @@
|
|
63
63
|
<div class="filename"></div>
|
64
64
|
|
65
65
|
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
# 追記
|
72
|
+
|
73
|
+
今回の課題はlabelのforが消えてしまうため、
|
74
|
+
|
75
|
+
削除ボタンを押した後ファイル選択が効かないことです
|
76
|
+
|
77
|
+
削除せずに非表示にするとかで対応してもよいかもしれません
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```javascript
|
82
|
+
|
83
|
+
<script>
|
84
|
+
|
85
|
+
$(function(){
|
86
|
+
|
87
|
+
$(":file").on('change',function(){
|
88
|
+
|
89
|
+
var file = $(this).prop('files')[0];
|
90
|
+
|
91
|
+
$(this).siblings('.input-label').hide().after($('<button class="file_clear">削除</button>'));
|
92
|
+
|
93
|
+
$(this).siblings('.filename').text(file.name);
|
94
|
+
|
95
|
+
});
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
$(document).on('click', '.file_clear',function(){
|
100
|
+
|
101
|
+
$(this).siblings(':file').val(null);
|
102
|
+
|
103
|
+
$(this).siblings('.filename').text("選択されていません");
|
104
|
+
|
105
|
+
$(this).siblings('.input-label').show()
|
106
|
+
|
107
|
+
$(this).remove();
|
108
|
+
|
109
|
+
});
|
110
|
+
|
111
|
+
});
|
112
|
+
|
113
|
+
</script>
|
114
|
+
|
115
|
+
<div>
|
116
|
+
|
117
|
+
<input type="file" id="01" name="01" class="none">
|
118
|
+
|
119
|
+
<label for="01" class="input-label">ファイルを選択</label>
|
120
|
+
|
121
|
+
<span class="filename">選択されていません</span>
|
122
|
+
|
123
|
+
</div>
|
124
|
+
|
125
|
+
<div>
|
126
|
+
|
127
|
+
<input type="file" id="02" name="02" class="none">
|
128
|
+
|
129
|
+
<label for="02" class="input-label">ファイルを選択</label>
|
130
|
+
|
131
|
+
<span class="filename">選択されていません</span>
|
132
|
+
|
133
|
+
</div>
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
```
|