/* * jQueryテストプラグイン */ ;(function($){ $.fn.myTest = function(options){ var opts = jQuery.extend({}, $.fn.myTest.defaults, options); return this.each(function(){ $(this).css({width : opts.width, height : opts.height, background : opts.color}); }); }; //デフォルト値 $.fn.myTest.defaults = { height : '200px', width : '300px', color : 'blue' }; })(jQuery);
もし、引数にてパラメータを渡した場合デフォルト値が上書きされる。
$(function(){ $("#test").myTest({width : '400px'}); }) <div id="test"></div>