0
好吧,所以我不能得到它如何跨jQuery插件共享设置,无论我做什么我的设置获取覆盖时,循环槽元素。这里是我的代码: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,但至少对我来说目前还没有效果。