我利用dropzone.js实现了文件上传功能。我像这样创建表单:
<form action="/target-url" id="my-dropzone" class="dropzone"></form>
<script>
// myDropzone is the configuration for the element that has an id attribute
// with the value my-dropzone (or myDropzone)
Dropzone.options.myDropzone = {
init: function() {
this.on("addedfile", function(file) {
// Create the remove button
var removeButton = Dropzone.createElement("<button>Remove file</button>");
// Capture the Dropzone instance as closure.
var _this = this;
// 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.
_this.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);
});
}
};
</script>我已经在html文件头中添加了dropzone.js文件。但是,当我将一个文件拖入框中时,我得到了以下错误:
Uncaught ReferenceError: Dropzone is not defined请帮个忙。
发布于 2014-06-18 18:30:05
例如,您可以使用非常简单的代码
myDropzone.on("addedfile", function(file) {
file.previewElement.addEventListener("click", function() { myDropzone.removeFile(file); });
});https://stackoverflow.com/questions/22994031
复制相似问题