进来研究jquery扩展插件的方法,尝试了网上好多案例。最后还是感觉这种方式最为合适,易懂好掌握。先来看看实例:
(function (){
$.fn.a = function (opt){
settings = $.extend({
left: 20,
right: 30
}, opt);
var opts = [];
opts = $.extend({}, $.fn.a.defaults, settings);
return this.each(function (){
$.fn.extend(this, a);
this.opts = opts;
$(this).bind("click",this.alerts).bind("click", this.con);
})
}
var a = {
alerts: function (){
alert(this.opts.left)
},
con: function (){
console.log(this.opts.width)
}
}
$(window).a({
width: "200px",
height: "200px"
})
})(Zepto)