我今天也学习了做jquery插件
先贴代码
(function ( $ ) { var id=33; $.fn.validate=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. alert(settings.color); } }( jQuery ));
1.jquery插件传递参数通过json
2.jquery 函数内默认属性json定义 ,使用$.extend()函数可以在未定义参数时,使用默认参数
var settings = $.extend({ // 这是默认的参数 color: "#556b2f", backgroundColor: "white" }, options );
3.定义私有对象
(function ( $ ) { }( jQuery ));