同一页面内文件输入html5(js)和多字段中文件的限制数量

问题描述 投票:-1回答:1

您好,我试图找到一个很好的解决方案来限制文件输入中的文件数量我的问题是我也需要找到通用的解决方案,因为html是动态生成的,并且我在同一页面中有多个输入(并且我想要不同的限制对等字段)html代码previwe

<input type="file" name="micker[file_upload2][]" accept=".pdf" id="fileupload2" placeholder="Upload field2 mulitple" aria-label="Upload field2 mulitple" class="inputfile required invalid" multiple="" style="margin:0" maxuploads="2" aria-required="true" required="required" aria-invalid="true">

我需要添加限制函数对等字段,例如前2个和后10个我的想法是激发https://stackoverflow.com/a/15855085/2822359max-uploads = 6到我的html和upload.js

jQuery(document).ready(function ($) {
           $("body").change(function () {
               var numFiles = $("input",this)[0].files.length;
               var maxuploads = $("input",this)[0].attr(\'data-maxuploads\').toString();
               alert(numFiles);
               if (numFiles > maxuploads ) {
                   alert(\'Your Message\');
                   }else {
                   maxuploads = maxuploads + 1;
                       }
                   });
           });
           });

错误

Uncaught TypeError: Cannot read property 'length' of undefined

感谢您的帮助

javascript jquery file
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.