gpt4 book ai didi

jquery - HTML5 获取输入文件计数变化

转载 作者:搜寻专家 更新时间:2023-10-31 22:48:09 26 4
gpt4 key购买 nike

我需要使用 html5 文件 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>

查询

$('input[type=file]').change(function () {
$fileCount = $(this).files.length;
$(this).parent('.form-row').find('.form-text').html($fileCount + 'Selected');
})

有人知道我错在哪里吗?感谢所有帮助

最佳答案

files 不是 jQuery 对象的属性。

改变这个:

$fileCount = $(this).files.length;

收件人:

$fileCount = this.files.length;

您还可以缩小选择器:

$('input[type=file]').change(function () {
fileCount = this.files.length;
$(this).prev().text(fileCount + 'Selected');
})

http://jsfiddle.net/hHgEF/

关于jquery - HTML5 获取输入文件计数变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12557453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com