How does JQuery customize plug-ins -- $. fn usage, jquery. fn
JQuery provides many plug-ins, which are roughly searched and cannot be described as follows:
I clicked a few and looked at the results. They found that they were quite exquisite. web development needed more aesthetics than Javascript. I can only say that JS is just a foundation.
It is a good news for developers. However, so many plug-ins sometimes not all meet our needs. For example, sometimes we only need a ship engine, but now we only have a ship. We also need to take the ship apart, or sometimes we don't need any parts at all. At this time, we need to do it ourselves.
For example, I have previously written a Tab control. Now I want to make it a plug-in. Let's take a look at this Demo:
First, write a separate JS file:
// JavaScript Document <span style = "color: # FF0000;"> <strong> // $. fn is the extension plug-in method </strong> </span> (function ($) {// form a closure and define the scope $. fn. miaovTab = function () {var This = this; $ (this ). find ('input '). click (function () {$ (This ). find ('input '). attr ('class', ''); $ (This ). find ('div '). fadeOut (); $ (this ). attr ('class', 'active'); $ (This ). find ('div '). eq ($ (this ). index ()). fadeIn () ;};};} (jQuery );
Then, add the following code to the page:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
You can click the three buttons in the browser to switch the Tab.
Now, I have practiced creating plug-ins. When we encounter an inappropriate plug-in next time, we can hand-write or extract some of the source code from the Demo, and then use the code to make our own lightweight plug-ins.
PS: attaches a very beautiful JQuery plug-in Library: http://www.jq22.com/