如何在多个文件上传器中启用提交按钮,直到出现条件?

我正在做一个WebApp,在那里人们将上传2张图像,我需要通过python代码来传递这些图像。因此,我只想让他们在上传2张图像后发送。

但我无法将其推断为我的情况:


<!DOCTYPE html>

<html>

<head>

    <link rel="stylesheet" type="text/css" href="https://unpkg.com/file-upload-with-preview@3.4.3/dist/file-upload-with-preview.min.css">

</head>



<body>

  <!-- Uploader -->

<div class="custom-file-container" data-upload-id="myImage">

    <label>Upload your images <a href="javascript:void(0)" class="custom-file-container__image-clear" title="Clear Image">&times;</a></label>


    <label class="custom-file-container__custom-file" >

      <form id="upload-form" action="{{url_for('upload')}}" method="POST" enctype="multipart/form-data">

      <input type="file" class="custom-file-container__custom-file__custom-file-input" accept="image/*" aria-label="Choose File" multiple>

      <input type="hidden" name="MAX_FILE_SIZE" value="10485760" />

      <span class="custom-file-container__custom-file__custom-file-control"></span>

    </label>

    <div class="custom-file-container__image-preview"></div>

</div>

<input type="submit" name="send" disabled/>

</div>



<script src="https://unpkg.com/file-upload-with-preview@3.4.3/dist/file-upload-with-preview.min.js"></script>


<script>

      var upload = new FileUploadWithPreview('myImage', {showDeleteButtonOnImages: true, text: {chooseFile: 'Nom del fitxer', browse: 'Examina'}})

</script>


<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>


<script>


$(document).ready(

    function(){

        $('input:file').change(

            function(){

                if ($(this).val()) {

                    $('input:submit').attr('disabled',false);; 

                } 

            }

            );

    });


</script>


</body>

</html>

添加的最后一个脚本是第一个链接中给出的解决方案,它可以正常工作,但不是我想要的。


文件上传器代码来自https://github.com/promosis/file-upload-with-preview,在这里我看到有一种称为selectedFilesCount的方法可能有用。


感谢您的时间,如果您在我的代码中看到一些废话,则感到抱歉,但是我是这些语言的新手...


慕哥6287543
浏览 100回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript