[js]
/*
* 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);
[/js]
もし、引数にてパラメータを渡した場合デフォルト値が上書きされる。
[js]
$(function(){
$("#test").myTest({width : ‘400px’});
})
<div id="test"></div>
[/js]