$.fn. 給jQuery擴展插件

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章