1.颜色插件,比用css方便些
//1.插件编写 ;(function ($) { $.fn.extend({ "color":function(value){ return this.css("color",value); } }); })(jQuery); //2.插件应用 $(function () { $("div:eq(1)").color("red"); });
1.表格各行变色插件
//1.插件编写 ;(function ($) { $.fn.extend({ "alterBgColor":function(options){ options = $.extend({ odd:"odd", even:"even", selected:"selected" },options); this.each(function(){ $("tbody>tr:odd", this).addClass(options.odd); $("tbody>tr:even", this).addClass(options.even); $("tbody>tr",this).click(function(){ var hasSelected = $(this).hasClass(options.selected); $(this)[hasSelected ? "removeClass":"addClass"](options.selected).find(":checkbox").attr("checked",!hasSelected); }); }); } }); })(jQuery); //2.插件应用 $(function () { $("table").alterBgColor(); });