使用jQuery在输入框中计数文件数? [英] Count number of files in input box with jQuery?

查看:123
本文介绍了使用jQuery在输入框中计数文件数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何计算文件上传输入使用jQuery文件的数量?

How can I count the number of files that are in the file upload input using jQuery?

我已经尝试过,但它总是返回1:

I have tried this but it always returns 1:

$("body").on("change", ".create-album .custom-file-input .createAlbumFileUpload", function(){   

    var numFiles = $("input:file", this).length;
    alert(numFiles);
});

我的HTML:

<form enctype="multipart/form-data" class="createAlbumFileUpload">
    <input type="file" name="uploadFile[]" multiple="multiple"/>
</form>

我发现这个 jsFiddle 另一个问题,询问同样的事情,但是我不明白为什么我的工作不工作。

I found this jsFiddle on another question asking the same thing, however I can't see why mine isn't working?

推荐答案

您提供的小提琴包含了答案。

The fiddle you provided contains the answer.

var numFiles = $("input:file", this)[0].files.length;

http: //jsfiddle.net/xvLAc/1/

这篇关于使用jQuery在输入框中计数文件数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆