A simple example of how to implement the table query function in jquery plug-in mode _jquery

Source: Internet
Author: User
Tags extend

1. Write the plugin section, as follows:

;(function ($) {

$.fn.plugin = function (options) {

var defaults = {

//various properties, various parameters

}

var    options = $.extend (defaults, options);

 This.each (function () {

//feature code

var _this = this;

});

}

) (JQuery);

Attach an example:

;(function ($) {$.fn.table = function (options) {var defaults = {//arguments, properties Evenrowclass: ' Evenrow ', Oddrowclass: ' Oddrow ', Currentrowclass: ' CurrentRow ', EventType: ' MouseOver ', Eventty

    Pe2: ' Mouseout ',} var options = $.extend (defaults, options);
      This.each (function () {//function code var _this = $ (this);
      Even row _this.find (' Tr:even:not (' #thead ') '). addclass (Options.evenrowclass);
      _this.find (' #thead '). Removeclass (Options.evenrowclass);

      Odd row _this.find (' tr:odd '). addclass (Options.oddrowclass);
      /*_this.find (' tr '). MouseOver (function () {$ (this). addclass (Options.currentrowclass);
      }). mouseout (function () {$ (this). Removeclass (Options.currentrowclass);
      } */_this.find (' tr '). Bind (Options.eventtype, function () {$ (this). addclass (Options.currentrowclass);

      }); _this.find (' tr '). Bind (Options.eventtype2, function (){$ (this). Removeclass (Options.currentrowclass);

    });
    });
  return this; }) (JQuery);

The HTML part invokes the plugin as follows:

 
 

After the page is loaded successfully, execute

; $ (function () {

$ (' #table1 '). Table ({
  
 //arguments, properties
 evenrowclass: ' EvenRow1 ',
ODDROWCL Ass: ' OddRow1 ',
 currentrowclass: ' CurrentRow1 ' 
 });



Attached code:

<!doctype html>  

Through this example, we learned the JQuery object-level plug-in development

The above jquery plug-in way to realize the table query function of a simple example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.