我需要使用html5 File API来获取输入文件元素中选择的文件数量,并在另一个元素中设置值。
HTML
<div class="form-row">
<label>Main Image</label>
<div class="form-text">None Selected</div>
<input type="file" class="txtbox" name="proImage" id="proImage" value="" />
</div>
Jquery的
$('input[type=file]').change(function () {
$fileCount = $(this).files.length;
$(this).parent('.form-row').find('.form-text').html($fileCount + 'Selected');
})
任何人都知道我哪里出错了?所有帮助表示赞赏
答案 0 :(得分:6)
files
不是jQuery对象的属性。
改变这个:
$fileCount = $(this).files.length;
要:
$fileCount = this.files.length;
您还可以缩小选择器:
$('input[type=file]').change(function () {
fileCount = this.files.length;
$(this).prev().text(fileCount + 'Selected');
})