Jquery Plug-in Learning Example 1 plug-in manufacturing instructions and Tableui optimization _jquery

Source: Internet
Author: User
Tags extend
First of all, the jquery production method, jquery for the development of expansion arch two methods, respectively:
Jquery.extend (object); To extend the jquery class itself. Adds a new method to the class.
JQuery.fn.extend (object); Add methods to the JQuery object.
1.1, JQuery.fn.extend (object):
An example of a jquery reference manual can be relied on:
Copy Code code as follows:

$.fn.extend ({
Check:function () {
Return This.each (function () {this.checked = true;});
},
Uncheck:function () {
Return This.each (function () {this.checked = false;});
}
});

Use:
Copy Code code as follows:

$ ("Input[type=checkbox]"). Check ();
$ ("Input[type=radio]"). Uncheck ();

1.2, Jqueryjquery.extend (object)
Extend the jquery object itself. Used to add new functions to the jquery namespace.
JQuery Code:
Copy Code code as follows:

$.extend ({
Min:function (A, b) {return a < b a:b;},
Max:function (A, b) {return a > b a:b;}
});

Use:
Copy Code code as follows:

$.min (2,3); => 2
$.max (4,5); => 5

Second, Tableui specific plug-in sample code is as follows:
Copy Code code as follows:

/*
* Tableui 0.2
* Don't write the copyright, hehe
* date:4/1/2010
* Use Tableui to make it easy to use the table hints experience. The first features are the odd and even row color alternating, the mouse move to highlight
* 0.2 version combined with 25 tips on the "Commissar" that did some optimization, learning, please correct me.
*/
(function ($) {
$.fn.tableui = function (options) {
Default parameters
var defaults = {
Evenrowclass: "Evenrow",
Oddrowclass: "Oddrow",
Activerowclass: "Activerow"
};
Overriding default values with incoming parameters
options = $.extend (defaults, options);
Table objects
var thistable = $ (this);
Add odd even line color
Thistable.find ("Tr:even"). addclass (Options.evenrowclass);
Thistable.find ("Tr:odd"). addclass (Options.oddrowclass);
Binds the mouse to move events without having to bind the events to each row.
Thistable.live ("MouseOver", function (e) {
Gets the target object parent TR of the mouse
$ (e.target). Parent (). addclass (Options.activerowclass);
Block event bubbling
return false;
}). Live ("Mouseout", function (e) {
$ (e.target). Parent (). Removeclass (Options.activerowclass);
return false;
});
};
}) (JQuery);

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.