dropzone.js给出错误“无效的dropzone元素";在没有Dropzone的页面上 [英] dropzone.js is giving error "Invalid dropzone element" on page without a dropzone

查看:557
本文介绍了dropzone.js给出错误“无效的dropzone元素";在没有Dropzone的页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dropzone js,在需要dropzone的页面上效果很好.在任何其他页面上,它都会给我一个"Invalid dropzone element"错误消息,并导致其他JavaScript出现问题.

I'm using dropzone js and it's working great on pages that I require a dropzone. On any other page though it's giving me a "Invalid dropzone element" error message and causing issues with my other javascript.

我有一个自定义JS文件(该文件在dropzone.js文件之后立即加载),并且在文件的顶部,我有以下代码行:

I have a custom JS file (which loads immediately after the dropzone.js file) and at the very top of the file I have the following line of code:

Dropzone.autoDiscover = false;

这应该阻止它查看我没有以编程方式启用它的任何页面.该错误只会在存在有效拖放区的页面上消失.

This should stop it from looking at any page where I'm not enabling it programatically. The error only goes away on pages where there is a valid dropzone.

我还在dropzone.js的第1470行上设置了以下代码,尝试也在其中启用它:

I also set the following code on line 1470 on dropzone.js to try and enable it there too:

Dropzone.autoDiscover = false;

如何摆脱这个错误?

推荐答案

使用纯JS,您可以尝试以下方法:

With pure JS you can try this:

if (document.getElementById('DropzoneElementId')) {
  var myDropzone = new Dropzone("div#DropzoneElementId", { url: "/file/post"});
  // other code here
}

或者如果您使用jQuery:

or if you use jQuery:

if ($('#DropzoneElementId').length) {
  $("div#DropzoneElementId").dropzone({ url: "/file/post" });
  // other code here
}

这篇关于dropzone.js给出错误“无效的dropzone元素";在没有Dropzone的页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆