jQuery,如何检查插件是否已经应用于div?

AnA*_*ice 7 jquery jquery-ui jquery-plugins

jQuery文件上传器:https://github.com/blueimp/jQuery-File-Upload

我正在使用上面的插件.如何在jQuery中查看fileUpload是否已经应用?

我现在收到以下错误:

Uncaught FileUpload with namespace "file_upload" already assigned to this element
jQuery.jQuery.extend._Deferred.deferred.resolveWithjquery-1.5.1.js:869
donejquery-1.5.1.js:6591
jQuery.ajaxTransport.send.callbackjquery-1.5.1.js:7382
Run Code Online (Sandbox Code Playgroud)

有没有办法在我的函数调用之前检查:

$('.upload').fileUploadUI({
 .........
 .........
 .........
Run Code Online (Sandbox Code Playgroud)

谢谢

Dut*_*432 16

您可以添加/设置一个类作为排序的标志.在这种情况下,我们将添加一个名为的类applied

//scroll through each upload item
$('.upload').each(function(){

    //Make sure class is not found
    if (!$(this).hasClass('applied')) 

        //Apply Class and Upload Plugin
        $(this).addClass('applied').fileUploadUI({...}); 
}); 
Run Code Online (Sandbox Code Playgroud)

如下所述更新yoavmatchulsky,您也可以更轻松地做到

$('.upload:not(.applied)').addClass('applied').fileUploadUI({...});
Run Code Online (Sandbox Code Playgroud)

  • 或者使用$('.upload:not(.applied)').fileUploadUI(...) (5认同)