学习jquery插件的入门写法
$(function(){ $.fn.album_tree = function(options){ var defaults = { conhtml: function(){ }, }; var settings = $.extend({}, defaults, options); $this = $(this); // 左侧菜单 $this.on('click', '.atree_one a', function(evt){ slc = $('.atree_one a', evt.selector); $this = $(this); if($this.hasClass('open')){ $this.removeClass('open'); $this.nextAll().remove(); }else{ $this.addClass('open'); // 加载其他内容 settings.conhtml(pid); } // 选中当前 slc.removeClass('ck'); $this.addClass('ck'); }); } });
调用方法
$(".uimg_menu").album_tree({ conhtml: function(pid){ album_slist(pid); $("#uimg_menu_type").val(pid); //小图标选中则标记 } });