How does JQuery customize plug-ins -- $. fn usage
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// $. Fn is the extension plug-in method(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:
<Script type = text/javascript src = E: BS learning jqueryjqueryjquery-1.7.2.min.js for various engineering files> </script> <script language = JavaScript type = text/javascript src = JS plug-in example. js> </script> <script> $ (function () {$ ('# div1 '). miaovTab () ;}); </script> 111112222233333
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.