如何限制html中的文件上传次数? [英] How do I limit the number of file upload in html?

查看:282
本文介绍了如何限制html中的文件上传次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想限制用户在输入标签中选择最多6个文件。目前,我的输入标签是这样的:

I want to limit user to select up to 6 files in the input tag. Currently, my input tag is like this:

<input type="file" name="question_pic" id="id_question_pic" multiple/>

我想限制用户最多选择6个文件。我可以在服务器端返回错误,但我希望客户端先更改它。

I would like to limit user to select up to 6 files. I can return an error on the server side but I want client side to change it first.

有没有办法做到这一点?

Is there a way to do that?

谢谢。

推荐答案

你可以使用这样的jQuery函数:

You can use a jQuery function like this:

$('.fileinput').change(function(){
    if(this.files.length>10)
        alert('Too many files')
});
// Prevent submission if limit is exceeded.
$('form').submit(function(){
    if(this.files.length>10)
        return false;
});

这篇关于如何限制html中的文件上传次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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