jQuery文件上传多个实例错误

时间:2016-03-02 21:37:00

标签: javascript jquery file-upload

我已经使用jquery文件上传插件(https://github.com/blueimp/jQuery-File-Upload)完成了文件上传。但现在,我不知道如何解决这个问题:我有这样的HTML代码:

<form id="form-1"></form>
<input type="file" class="file-upload" id="file-1" name="file" form="form-1" />
<form id="form-2"></form>
<input type="file" class="file-upload" id="file-2" name="file" form="form-2" />




    $('input[type="file"][name="file"].file-upload').each(function(){
            var self = $(this);
            $(this).fileupload({
                url: window.fileUpload.uploadUrl,
                dataType: 'json',
                dropZone: self,
                fileInput: self
            });
});

但是有问题,当我将文件放在第一次输入时,它上传文件2次 - 对于每个输入。我不知道如何解决这个问题。你有任何解决方案吗?

编辑: 我发现,上传只完成一次,但两次被称为&#34; fileuploaddone &#34;事件

解决: jQuery文件上传实例在一个文件输入上启动了两次。

1 个答案:

答案 0 :(得分:0)

这是因为您没有导入jquery min-js文件并在<script type="text/javascript">您的代码</script>下正确编写代码