Implement the table query function using the jquery plug-in, jquerytable
1. Write the plug-in section as follows:
; (Function ($ ){
$. Fn. plugin = function (options ){
Var defaults = {
// Various attributes and Parameters
}
Var options = $. extend (defaults, options );
This. each (function (){
// Function Code
Var _ this = this;
});
}
}) (JQuery );
Attached example:
1 ;(function($){ 2 $.fn.table = function(options){ 3 var defaults = { 4 //arguments , properties 5 evenRowClass : 'evenRow', 6 oddRowClass : 'oddRow', 7 currentRowClass : 'currentRow', 8 eventType : 'mouseover', 9 eventType2 : 'mouseout',10 } 11 var options = $.extend(defaults, options);12 13 this.each(function(){14 15 //function code16 var _this = $(this);17 //even row18 _this.find('tr:even:not("#thead")').addClass(options.evenRowClass);19 //_this.find('#thead').removeClass(options.evenRowClass);20 // odd row 21 _this.find('tr:odd').addClass(options.oddRowClass);22 23 /*_this.find('tr').mouseover(function(){24 $(this).addClass(options.currentRowClass);25 }).mouseout(function(){26 $(this).removeClass(options.currentRowClass);27 });*/28 29 _this.find('tr').bind(options.eventType, function(){30 $(this).addClass(options.currentRowClass);31 });32 33 _this.find('tr').bind(options.eventType2, function(){34 $(this).removeClass(options.currentRowClass);35 });36 37 });38 return this;39 }40 })(jQuery);
Some html call plug-ins are as follows:
$ () ;==$ (Function () {}) ;=$ (document). ready (); after the page is loaded successfully, execute
; $ (Function (){
$ ('# Table1'). table ({
// Arguments, properties
EvenRowClass: 'evenrow1 ',
OddRowClass: 'oss row1 ',
CurrentRowClass: 'currentrow1'
});
});
Code attached:
1 <! Doctype html> 2
This example shows how to develop jquery object-level plug-ins.