如果条件不满足,如何在Dropzone.js中取消/中止上传?

编程入门 行业动态 更新时间:2024-10-11 21:29:48
本文介绍了如果条件不满足,如何在Dropzone.js中取消/中止上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 Dropzone.js 上传文件。现在我想检查一个文件是否已填写,如果没有,则取消上传。

I'm using Dropzone.js to upload files. Now I want to check a filed is filled or not, and if it isn't then cancel the upload.

我的HTML代码:

<input type="text" name="title" id="title" placeholder="Type the title of the album"> <form action="file-upload.cgi" enctype="multipart/form-data" class="dropzone" id="dropzoneform"></form>

我的jQuery代码:

My jQuery code:

Dropzone.autoDiscover = false; $('.dropzone').dropzone({ acceptedFiles: 'image/jpeg', init: function() { this.on('sending', function() { if ( $('#title').val().length > 0 ) { // just start automatically the uploading } else { // need a code to cancel the uploading } } } });

当 #title 的长度为0时,如何取消上传?

How can I cancel the uploading when the #title's length is 0?

推荐答案

这个怎么样

Dropzone.autoDiscover = false; $('.dropzone').dropzone({ acceptedFiles: 'image/jpeg', init: function() { var that = this; that.on('sending', function(file) { if ( $('#title').val().length <= 0 ) { that.removeFile(file); } } } });

更多推荐

如果条件不满足,如何在Dropzone.js中取消/中止上传?

本文发布于:2023-10-28 01:22:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535082.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不满足   条件   上传   如何在   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!