我正在尝试为对话模式开发一个jquery组件,我不知道如何从所有组件函数访问设置。我需要从open函数访问settings.zIndex
,它似乎无效。
(function($) {
var methods = {
init: function(options) {
var defaults = {
bgClass: "fancy-dialog-bg",
bgShow: null,
zIndex: 100,
show: null
};
var settings = $.extend(defaults, options);
return this.each(function() {
var obj = $(this).hide().css("position", "fixed").css("z-index", settings.zIndex).css("left", "300px").css("top", "200px");
});
},
open: function() {
// alert(settings.zIndex); not working
var tes = $("<div></div>").css("backgroundColor", "#f00").css("position", "fixed").css("z-index", "99").css("width", "50%").css("height", "100%").css("left", "0").css("top", "0");
$('body').append(tes);
var obj = $(this);
obj.show();
},
close: function() {
var obj = $(this);
$("#fancy-dialog-bg-" + obj.attr('id')).remove();
obj.hide();
}
};
$.fn.fancyDialog = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
}
else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
}
else {
$.error('Method ' + method + ' does not exist.');
}
};
})(jQuery);
答案 0 :(得分:0)
更改此行:
var settings = $.extend(defaults, options);
到此:
this.settings = $.extend(defaults, options);
然后,设置将是您可以通过以下方式访问的方法对象的属性:
methods.settings