私は次のHTMLを持っています:
<input id="upload1" type="file" /><br/>
<input id="upload2" type="file" /><br/>
<input id="upload3" type="file" /><br/>
<input id="upload4" type="file" /><br/>
<input id="upload5" type="file" /><br/>
<span id="label" style="color:red; display:none">
Wrong filetype!
</span>
そして、次の jQuery:
$('input:file').change(function(){
var ext = $(this).val().split('.').pop().toLowerCase();
$('#label').toggle(ext != 'pdf');
});
私がやりたいことは、#label
5 つの要素すべてinput:file
が検証に合格した場合にのみトグルすることです (pdf 拡張子のみ)。またはファイルが選択されていません。
現時点では、.jpg
最初に を選択すると が#label
表示され、次に を選択する.pdf
と が#label
消えます。5 つの要素.jpg
のうちの 1 つでまだ選択されているため、これは正しくありません。input:file
編集:ここでフィドル