【问题标题】:Dropzone js can't get addEventListener when clicked on button in FireFox单击 FireFox 中的按钮时,Dropzone js 无法获取 addEventListener
【发布时间】:2015-07-27 22:30:43
【问题描述】:

我试图解决这个问题,但我不能。 将文件上传到 FireFox 时,我无法上传, 但是文件会上传到 Opera 中。 在 Dropzone.js 中,我使用 bootstrap 和 jquery 作为库。

在我看来,问题在于 addEventListener? 带有萤火虫的示例视频:enter link description here

片段:

Dropzone.options.myDropzone = {

		// Prevents Dropzone from uploading dropped files immediately
		autoProcessQueue: false,
		parallelUploads: 10,
		thumbnailWidth: 120,
		thumbnailHeight: 120,
		init: function() {

			var submitButton = document.querySelector("#submit-all");
			var myDropzone = this;

				submitButton.addEventListener("click", function() {
			  		myDropzone.processQueue(); // Tell Dropzone to process all queued files.
			  	});

			    this.on("addedfile", function(file) {
			        // Create the remove button
			        var removeButton = Dropzone.createElement("<button class='btn btn-xs btn-warning'>Remove file</button>");

			        // Listen to the click event
			        removeButton.addEventListener("click", function(e) {
			          // Make sure the button click doesn't submit the form:
			          e.preventDefault();
			          e.stopPropagation();

			        // Remove the file preview.
			        myDropzone.removeFile(file);
			        //   // If you want to the delete the file on the server as well,
			        //   // you can do the AJAX request here.
			        });

			        // Add the button to the file preview element.
			        file.previewElement.appendChild(removeButton);
				});
				
		} //dropzone init
	}; //dropzone options
<script src="https://raw.githubusercontent.com/enyo/dropzone/master/dist/dropzone.js"></script>

<form action="upload/do_upload" class="dropzone" id="my-dropzone"></form>
<button type="button" class="btn btn-primary"><span id="submit-all">Submit all files</span></button>
<button type="button" class="btn btn-default"><a href="upload">Reset</a></button>

【问题讨论】:

    标签: dropzone.js


    【解决方案1】:

    这里有一个 SPAN id="submit-all"

    &lt;button type="button" class="btn btn-primary"&gt;&lt;span id="submit-all"&gt;Submit all files&lt;/span&gt;&lt;/button&gt;

    那么你就有了一个 querySelector:

    var submitButton = document.querySelector("#submit-all");

    按钮有一个点击事件,而不是跨度。也许如果您将第一行更改为此它应该可以工作:

    &lt;button type="button" id="submit-all" class="btn btn-primary"&gt;&lt;span&gt;Submit all files&lt;/span&gt;&lt;/button&gt;

    试一试并告诉我们。

    【讨论】:

    • +Guilherme Melo 现在,已经过去了很长时间,大约 8 个月前。我不再使用 dropzone。而且我不知道我现在在做什么?也许这个问题对某人有用?感谢您的回答,真的很抱歉。如果问题没有用 - 如何删除它?
    猜你喜欢
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多