Jquery plugin learning instance 1 plugin creation instructions and tableUI optimization

Source: Internet
Author: User

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

Two, Tableui specific plug-in sample code is as follows:
Copy code code as follows:
//
* Tableui 0.2
* Don't write copyright, hehe
* date:4/1/2010
* Use Tableu I can easily use the table hints to experience. First to provide the function of the odd and even row color alternating, mouse move high display
* 0.2 version combined with 25 tips on the "Commissar" that did some optimization, learning, please correct me.
*/
(function ($) {
$.fn.tableui = function (options) {
//default parameter
var defaults = {
Evenrowclass: " Evenrow ",
Oddrowclass:" Oddrow ",
Activerowclass:" Activerow "
};
//Overrides default value with incoming parameters
options = $.extend (defaults, options);
//Table Object
var thistable = $ (this);
//Add odd-even row color
Thistable.find ("Tr:even"). addclass (Options.evenrowclass);
Thistable.find ("tr:odd"). addclass (Options.oddrowclass);
//Bind mouse move events, do not have to bind events to each row.
Thistable.live ("MouseOver", function (e) {
//Get the target object's parent TR
$ (e.target) that the mouse refers to. 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.