;(function($){ $.fn.pluginName = function(options){ var defaults = { //自定义默认的各种参数 evenRowClass:"evenClass", oddRowClass:"oddClass", currentRowClass:"currentClass", eventType:"mouseover", eventType2:"mouseout" }; var options = $.extend({}, defaults, options); this.each(function(){ //实现插件功能代码 var _this = $(this); this.find("tr:even").addClass(options.evenRowClass); _this.find("tr:odd").addClass(options.oddRowClass); _this.find("tr").bind(options.eventType,function(){ $(this).addClass(options.currentRowClass) }); _this.find("tr").bind(options.eventType2,function(){ $(this).removeClass(options.currentRowClass) }) }) } })(jQuery); //调用插件 $(function(){ $("domElement").pluginName({ venRowClass:"evenClass", oddRowClass:"oddClass", currentRowClass:"currentClass", eventType:"mouseover", eventType2:"mouseout" }); });
jquery 对象级插件写法
最新推荐文章于 2019-08-30 17:23:10 发布