jQuery,如何检查插件是否已经应用于div?
jQuery文件上载程序: 我正在使用上面的插件。如何在jQuery中检查文件上传是否已应用 我现在得到以下错误:jQuery,如何检查插件是否已经应用于div?,jquery,jquery-ui,jquery-plugins,Jquery,Jquery Ui,Jquery Plugins,jQuery文件上载程序: 我正在使用上面的插件。如何在jQuery中检查文件上传是否已应用 我现在得到以下错误: 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.ajaxTra
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
是否有方法在调用函数之前进行检查:
$('.upload').fileUploadUI({
.........
.........
.........
谢谢您可以添加/设置类作为排序标志。在本例中,我们将添加一个名为
applicated
//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({...});
});
更新正如下面由yoavmatchulsky
指出的,您还可以更轻松地进行更新
$('.upload:not(.applied)').addClass('applied').fileUploadUI({...});
jQuery文件上传插件将对其文件上传处理程序的引用存储为对象。
错误消息“FileUpload with namespace“file_upload”已经分配给这个元素”来自插件自己对这个数据引用的检查 您可以通过以下方式初始化插件以防止此错误:
$('.upload').not(function () { return $(this).data('file_upload'); }).fileUploadUI({/*...*/});
你也可以这样做
if(undefined != $('.upload').data('blueimp-fileupload') ){
console.log( 'plugin already applied to the element' );
}
else console.log( 'plugin not applied to the element' );
或者使用$('.upload:not(.applicated')。fileUploadUI(…)这应该是答案。有时我们无法控制修改代码。(想想,第三方代码的selenium测试)简单而漂亮!