好的,所以我不知道如何在 jquery 插件之间共享设置,无论我做什么,我的设置在循环槽元素时都会被覆盖。这是我的代码:
(function ( $ ) {
var default_settings = {
auto_start: false,
tools: {}
};
function test(settings){
//here is the problem it gets wrong element
settings.tools.progress_bar.animate({
width: "100%"
});
}
var methods = {
init: function(element, options){
var settings = $.extend({}, default_settings, options);
settings.tools.progress_bar = $('<div class="test"></div>');
$(element).append(
settings.tools.progress_bar
);
if(settings.auto_start)
test(settings);
$.data(element, "settings", settings);
},
start: function(){
var settings = $.data(this, "settings");
test(settings);
}
}
$.fn.ajaxupload = function(method, options){
return this.each(function(){
if(methods[method])
return methods[method].apply(this, [options]);
else if(typeof method === 'object' || !method)
return methods.init(this, method);
});
}
})( jQuery);
我需要能够循环多个元素,然后调用公共函数来启动一些操作或其他东西,如下所示:
$(".container").ajaxupload();
$(".container2").ajaxupload();
//even though I call for container it will run animation for container2
$(".container").ajaxupload("start");
我也制作了jsfiddle,但至少目前对我来说它几乎不起作用。