如何限制多个输入上的最大项目(< input type =“file”multiple />) [英] How to limit maximum items on a multiple input (<input type="file" multiple />)

查看:122
本文介绍了如何限制多个输入上的最大项目(< input type =“file”multiple />)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想上传2件商品。
我如何限制多个输入文件中的最大项目

解决方案

您可以运行一些jQuery客户端验证检查:

  $(function(){
$(input [type ='submit'])。点击(function(){
var $ fileUpload = $(input [type ='file']);
if(parseInt($ fileUpload.get(0).files.length)> 2){
alert(你最多只能上传2个文件);
}
});
});

http://jsfiddle.net/Curt/ u4NuH /



但是请记住检查服务器端,客户端验证可以很容易地被绕过。


I want to upload just 2 items. How can I limit maximum items on an multiple input file

解决方案

You could run some jQuery client-side validation to check:

$(function(){
    $("input[type='submit']").click(function(){
        var $fileUpload = $("input[type='file']");
        if (parseInt($fileUpload.get(0).files.length)>2){
         alert("You can only upload a maximum of 2 files");
        }
    });    
});​

http://jsfiddle.net/Curt/u4NuH/

But remember to check on the server side too as client-side validation can be bypassed quite easily.

这篇关于如何限制多个输入上的最大项目(< input type =“file”multiple />)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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