Dropzone.js et le bouton supprimer
J'amusant les dropzone.js pour mettre en œuvre fichier de téléchargement. J'ai créer le formulaire comme ceci :
<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>
J'ai ajouté le dropzone.js dans le fichier d'en-tête du fichier html. Cependant lorsque je fais glisser un fichier à l'intérieur de la boîte, j'ai eu l'erreur suivante:
Uncaught ReferenceError: Dropzone is not defined
Merci de toute aide.
- mec, assurez-vous d'inclure les dropzone.js fichier!
Vous devez vous connecter pour publier un commentaire.
vous utilisez le code très simple
par exemple