進來研究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)