(function($){ $.fn.yourName = function(options){ //各种属性、参数 } var options = $.extend(defaults, options); this.each(function(){ //插件实现代码 }); }; })(jQuery);
各种属性、参数实现,定义插件函数名称tableUI
(function($){ $.fn.tableUI = function(options){ var defaults = { evenRowClass:"evenRow", oddRowClass:"oddRow", activeRowClass:"activeRow" } var options = $.extend(defaults, options); //合并多个对象为一个 this.each(function(){ //实现代码 }); }; })(jQuery);
(function($){ $.fn.tableUI = function(options){ var defaults = { evenRowClass:"evenRow", oddRowClass:"oddRow", activeRowClass:"activeRow" } var options = $.extend(defaults, options); this.each(function(){ var thisTable=$(this); //添加奇偶行颜色 $(thisTable).find("tr:even").addClass(options.evenRowClass); $(thisTable).find("tr:odd").addClass(options.oddRowClass); //添加活动行颜色 $(thisTable).find("tr").bind("mouseover",function(){ $(this).addClass(options.activeRowClass); }); $(thisTable).find("tr").bind("mouseout",function(){ $(this).removeClass(options.activeRowClass); }); }); }; })(jQuery);
$(function(){
$(".myTab").tableUI();
});
</script>