Implement the table query function using the jquery plug-in, jquerytable

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.