(function ($) {
$.fn.greenify = function(options) {
// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
color: "#556b2f",
backgroundColor: "white"
}, options);
// Greenify the collection based on the settings variable.
return this.css({
color: settings.color,
backgroundColor: settings.backgroundColor
});
};
}(jQuery));
취향 Docs 위의 코드는 간단한 jquery 플러그인을 만드는 방법을 보여줍니다. 여러 개를 허용하는 플러그인에 나열된 여러 매개 변수 중 하나만 제공하면 어떻게됩니까? 어느 것이 적용됩니까?
나는 사람이 이런 식으로 적용됩니다 여러 매개 변수를 취할 수있는 플러그인이있는 경우 :
매개 변수의 하나 개의 세트가 공급 된 경우 때 "확장"됩니다 옵션은 무엇 세트 $.doStuff({color:"black"},{color:"blue"});
?
E.x. $.doStuff({color:"black"});
jquery 플러그인에 선택적 매개 변수를 포함하는 방법
일반적으로 여러 매개 변수가 없어도 하나의 개체에 여러 속성이 있습니다. –